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.
Related
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",
I am running into a problem with zend mail sending functionality.
I have a functionality where we have set up some cron jobs and those cron jobs processes some php script and then sends a mail. Actually mails are going fine, but sometimes it is getting dropped into spam directory. After some research I have found that the return-path of mail body is causing problem. Since the mail sending script us as a root, so the return-path is root#domain.com and I want change it to support#domain.com
Is there any way I can achieve that.
Note: I did try to add that in headers, but it is not working.
It's return-path not reply-to... There's no such thing as reply-path :)
There are lots of parameters for being marked as spam and I'm not sure it's because of return-path only. You have to fix it though and you can try by altering the headers while sending:
$mail = new Zend_Mail();
$mail->addTo($this->email, $this->name)
->setFrom($message->from_email, $message->from_name)
->setSubject($message->subject)
->setBodyHtml($message->getHtmlEmailContent($subscriber))
->setBodyText($message->getTextEmailContent($subscriber))
->setReturnPath($settings->get('return_path'))
However SMTP servers might override this (gmail definitely does). Just open the email in raw and see if your header is there and if it's overriden or not.
If mails are marked as spam in your test account randomly you might want to check the contents and subject of your email. SPF records for your SMTP domain is important too.
See https://www.campaignmonitor.com/blog/post/1971/what-are-some-good-methods-for
and http://mailchimp.com/resources/guides/how-to-avoid-spam-filters/ for some details.
See this answer for the explanation of reply-to and return-path.
I'm building a daemon in php that checks for received emails which it then stores in the database leading them through a whole process. The thing is that I want to build some unit tests for this, for which I don't want to setup a whole mail server.
So for tests I want to somehow send emails to localhost, which should then be picked up by the daemon and processed further. So I tried the following:
$headers = 'From: me#mydomain.com \r\n Reply-To: me#mydomain.com \r\n X-Mailer: PHP/' . phpversion();
mail('www-data#localhost', 'THE SUBJECT', 'THE BODY IS HERE', $headers);
When I then run mail from the command line, I just get a message saying No mail for kramer65.
So my question; does anybody know how I can send emails to localhost in php, and how I can then read these emails from within php again? All tips are welcome!
[EDIT]
So I figured that it is sending an email to the www-data account, and not to my personal kramer65 account. I changed the to email address into kramer65#localhost, and when I now run mail I get
kramer65#php0:~$ mail
Mail version 8.1.2 01/15/2001. Type ? for help.
"/var/mail/kramer65": 1 message 1 new
>N 1 kramer65e#php0 Fri Apr 25 10:48 16/495 THE SUBJECT
&
My following question is now; how do I read or somehow get this email from within php?
This depends on how you have configured the php internal mail settings. If you configured it to use a local mail forward agent (sendmail or similar) then you should be able to send messages to a local account (not a local email address) by just specifying the account name. At least this is what such agents offer. Unless php explicitly prevents such usage it might be worth a try.
You cannot send to a local email address, since that requires an email server, specifically an smtp server (exim or the like). Without it there is no component that could accept an incoming message.
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
I have tested my email server on allaboutspam.com to see why the emails are beeing considered spam by hotmail and gmail servers.
The results was amongst other faults, the BATV.
This is the complete result from allaboutspam.com on my BATV:
BATV is a mechanism wherein an outgoing Email server adds a tag to the Envelope From address of all outgoing Emails. For example, if an Email address goes out with From address as <info#allaboutspam.com>, the Envelope From is changed to <prvs=SBDGAUJ=info#allaboutspam.com>, where 'SBDGAUJ' is the added tag. This tag is generated using an internal mechanism and is different for each email sent.
If any bounce is received by the Incoming email servers, they are checked to see if the Bounce address has the proper tag (in above case 'SBDGAUJ'). If not, the email is rejected.
Could somebody explain this in simpler words... How is it configured?
currently I have this setup when sending email with php:
$mail_message="text_text_text_text";
$headers="MIME-Version: 1.0"."\n";
$headers.="Content-type: text/plain; charset=UTF-8"."\n";
$headers.="From: Skuffen <no-reply#domain.se>"."\n";
$subject="SUBJECT HERE";
mail($email, '=?UTF-8?B?'.base64_encode($subject).'?=', $mail_message, $headers, '-fno-reply#domain.se');
This is a swedish language so you know (utf-8)...
Thanks
I think that you need to set this up in your Mail Transfer Agent. The PHP mail() command sends mail through the local sendmail (or compatible, like Exim, Postfix or Qmail) installation. That's where BATV needs to be configured.
If you are on a simple shared hosting, contact your hosting provider.