Strange case with php mail function and addition parameter “-f” - php

I using php and CodeIgniter to send email but after change the server have following strange problem.
Each mail are sent to recipient and to sender.
After long debug of this problem I came to the following case.
mail("example#exmaple.com",$title,$body,$headers);
Work as expect send email only to "example#exmaple.com".
But
mail("example#exmaple.com",$title,$body,$headers, "-f example#domain.com ");
Send email and on both mail "example#exmaple.com" and "example#domain.com"
The problem is I do not know why she sends both emails.
I want to send only to "example#exmaple.com"
Here's what it says about this parameter php.net
The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.
Obviously this parameter needs me but it is only for authentication and should not be sent to the e-mail "example#domain.com",

Related

PHP mail() configuration issue

Mails are sending from my php application using mail function. But client says it is from Mandril mail service. I logged into the Mandril account and found the mails sent. I checked the code. But didn't see any piece of code using the Mandril mail. It only uses php mail function. How can verify this?
My send mail path is configured like:
sendmail_path is /usr/sbin/sendmail -t -i -fadmin#abc.com -Fno-reply.
Note: I don't have access to the server.
The Mandril mail account was configured in sendmail confuguration. So when ever we use the php mail() function it will send through this account. Since the configuration lies in the send mail config file no any piece of code was there in the php code.

Return-Path header rewritten by postfix

I'm sending mails from PHP using postfix at ubuntu:
mail($to, $subject, $body, "Return-Path: <test#mail.com>");
Trying to set Return-Path header but it seems that postfix rewrites it to user#serverdomain
Found in postfix documentation message_drop_headers variable that by default has value bcc, content-length, resent-bcc, return-path
Tried to change it's value in postfix/main.cf but it gives warning on start:
/usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: message_drop_headers=bcc content-length resent-bcc
What could be the reason? How can I configure postfix not to rewrite Return-Path header?
Setting the Return-Path: header on outbound email is pointless because it will be replaced by the recipient's MTA. If you want to control what gets written there, set the envelope sender (traditionally, sendmail -f address#example.com)
In some more detail, when you send a message, there are two layers: An envelope, which specifies the actual recipients, and the message itself, which often contains headers with the same information ... but sometimes it doesn't, and sometimes those headers lie, blatantly.
When that message is delivered to a recipient, the receiving MTA (Sendmail or Postfix or Exchange or what have you) will copy the envelope sender information into the Return-Path: header, adding one if it's missing, and usually simply overwriting it if it already existed.
So it doesn't really matter how you configure Return-Path: on your outgoing server; in order to properly control this, you would need to control the receiving behavior on every server which delivers the message to a recipient.
As a trivial example, subscribe to a public mailing list, observe how the headers often say something like:
From: Popular mailing list <popular-list#example.com>
To: Popular mailing list <popular-list#example.com>
And yet it arrived in your inbox. How did that happen? Why, by way of the envelope recipient information. The list software basically adds a Bcc: to every subscriber, but also convinces the server to ignore the actual To: address in the headers. This is surprising until you realize that the headers actually don't matter, and only the envelope addresses actually control where the message is eventually delivered.
Briefly, the envelope is specified by the SMTP MAIL FROM: and RCPT TO: verbs which are defined in RFC5321 (originally 822) and the actual message (including all the headers) are communicatd in the SMTP DATA section which is really just pure data as far as SMTP is concerned at this point. Their specification is RFC5322 (née 822) and once a message is actually delivered, the receiving server will actually add some headers of its own, but the From: and To: headers are still just basically ignored.
The solution is to declare a smtp_generic_maps table in Postfix main.cf and list local user and corresponding email in it.
For example :
www-data test#mail.com
Look at https://www.postfix.org/generic.5.html for more infos.
Of course use only a real domain you manage and with at least a SPF record allowing sending mails from this server.

phpmailer complications for spam filters "-f"

My clients hosting service isn't accepting emails sent from the website that doesn't have "-f" at the start of the FROM address. This related to a recent outgoing SPAM filter they added.
Official response is:
“senders envelope of data” is missing certain elements
I use phpmailer, everything was working fine until now using SMTP authentication.
But now with phpmailer, this DOESN'T work
$mail->From = 'me#test.com';
Also doesn't work
$mail->From = '-f me#test.com';
Its invalid obviousdly, not a good looking email address.
I CAN get mail to actually send like this:
mail('me#test.com', 'the subject', 'the message', null, '-f me#test.com');
But that isn't phpmailer, this is the garden variety php function. So im trying to make PHPmailer add "-f " to the FROM automatically somehow.
Should I be adjusting the class files to somehow get around that? Stuck!
You've got your transports mixed up. -f in the mail() function is an additional parameter passed to the underlying sendmail binary that sets the envelope sender of the message (and officially it should not have a space after it, like -fme#test.com). However, it does not apply when you are sending via SMTP because you get control over that parameter with the Sender property. You should do this:
$mail->Sender = 'me#test.com';
If you send using SMTP it will use that as the envelope sender (as the content of the SMTP MAIL FROM command), and if you send via isMail() or isSendmail() transports, it will set the sender via the -f property.
Also make sure you're using the latest PHPMailer from GitHub.

PHP mail: What does -f do?

While troubleshooting a contact form with an e-mail host they told me to use '-f' in the from address of the php mail function. What does the "-f" flag do and why would that be a fix for allowing an e-mail to be delivered? I read some of the documentation but I'm not quite clear on it.
Example code:
mail($emailAddress, $mailSubject, $mailBody, $headers, '-f ' . $mailFrom);
PS: without the "-f" it works just fine for the big e-mail hosts (hotmail, gmail, etc, but for whatever reason not for the smaller host I'm working with)
Thanks
-f is a parameter to the mailer (usually sendmail). From the docs:
The additional_parameters parameter can be used to pass additional
flags as command line options to the program configured to be used
when sending mail, as defined by the sendmail_path configuration
setting. For example, this can be used to set the envelope sender
address when using sendmail with the -f sendmail option.
Here is the man page for sendmail, you can see what the -f option does:
-fname Sets the name of the ``from'' person (i.e., the sender of the
mail). -f can only be used by ``trusted'' users (normally
root, daemon, and network) or if the person you are trying to
become is the same as the person you are.
The -f option is to set the bounce mail address. Sending a message without one can negatively influence the spam-score that is being calculated over the message. Messages with low scores sometimes get filtered out for certain hosts.
You can use https://www.mail-tester.com/ to test the score of your message. You can expirement with or without the -f flag and see the score change.
It is a flag to mark the following text ($mailFrom) to be used as "from" address of the mail.
Have a look at: http://www.php.net/manual/en/function.mail.php

Mail() doesn't set From header with postfix

I am trying to send email with mail() it works but even if I set From: email <name> it is sent with the original email of my server.
Is there anyway to solve this? I have debian with postfix
Use -f mail#mail.com to the last param of mail() and it will work.

Categories