dolythgoe
asked on
PHP mailout and spam filters
Hi all,
I have a mailout script running on 2 load-balanced servers written in php. Setup like so:
It's sent out upon signup.
I'm a bit confused with how the mail is being sent as my hosts have a mailserver which I used to setup the accounts on and in gmail the mail arrives like this:
myDomain Mailer noreply@mydomain.com via vded-dc-002.servers.wirehi ve.net to me
What does the 'via' bit mean and will this impact the 'likelihood of spam' score in these filters?
It doesn't even show up in Hotmail - not even junk so completely blocked!
DNS and networking is not my strong point so if anyone can help explain this clearly would be most grateful.
Cheers
I have a mailout script running on 2 load-balanced servers written in php. Setup like so:
$headers = "From: myDomain Mailer <noreply@mydomain.com> \n";
$headers .= "To-Sender: \n";
$headers .= "X-Mailer: PHP\n"; // mailer
$headers .= "Reply-To: noreply@mydomain.com\n"; // Reply address
$headers .= "Return-Path: returns@mydomain.com\n"; //Return Path for errors
$headers .= "Content-Type: plain/text; charset=iso-8859-1"; //Enc-type
$subject = 'Account Activation';
mail($email, $subject, $message, $headers);
It's sent out upon signup.
I'm a bit confused with how the mail is being sent as my hosts have a mailserver which I used to setup the accounts on and in gmail the mail arrives like this:
myDomain Mailer noreply@mydomain.com via vded-dc-002.servers.wirehi
What does the 'via' bit mean and will this impact the 'likelihood of spam' score in these filters?
It doesn't even show up in Hotmail - not even junk so completely blocked!
DNS and networking is not my strong point so if anyone can help explain this clearly would be most grateful.
Cheers
The "via" is added by Google to alert Gmail users that the From address is not the same as the originating domain. Basically there is no accountability in email at all - every header can be completely phony, and this is how we get the spread of malware and spam.
The best way to avoid being branded as a spammer is to use SPF, the "Sender Policy Framework." (Google it). The second best way is to tell your clients to white-list your domain.
You might want to try omitting the headers completely and just sending the mail with three arguments. This will create a plain-text message. If you send this to your Gmail account, you can click on the message and fire the dropdown for "Show Original" to see all the headers, including anything that you web hosting company added to identify spammers.
The best way to avoid being branded as a spammer is to use SPF, the "Sender Policy Framework." (Google it). The second best way is to tell your clients to white-list your domain.
You might want to try omitting the headers completely and just sending the mail with three arguments. This will create a plain-text message. If you send this to your Gmail account, you can click on the message and fire the dropdown for "Show Original" to see all the headers, including anything that you web hosting company added to identify spammers.
ASKER
Thanks for that - the difficulty I'm having is understanding the load-balancer setup with DNS. With one web-server the dns is mapped to it but with a load-balanced setup, I have an IP for the load-balancer and 1 for each of the webservers with the dns record pointing to the load-balancer.
Is there some more records I need to add to the DNS settings to include these?
Is there some more records I need to add to the DNS settings to include these?
The only DNS records you need for this is a matching A and PTR record for the sending IP, which in this case sounds like your load balancer.
You are worried about spam filters and wondering about why the headers look like they do right?
If you paste the headers from one of the mails you sent to gmail, I can tell you exactly what is happening and why, how to fix it, and any other best practices.
You are worried about spam filters and wondering about why the headers look like they do right?
If you paste the headers from one of the mails you sent to gmail, I can tell you exactly what is happening and why, how to fix it, and any other best practices.
I thought the headers required '\r\n', not just '\n'. http://tools.ietf.org/html/rfc5322#section-2.2
Oh, and to add to the DNS records comment, SPF record should be used as well as Ray mentioned.
What Dave mentioned is an interesting idea on top of everything else.
Having headers will make this all much easier :)
What Dave mentioned is an interesting idea on top of everything else.
Having headers will make this all much easier :)
ASKER
Awesome, thanks for that. Well it's not the load-balancer sending the email, they are sent directly from either web server 1 or web server 2. The lb just splits the incoming traffic to either web1 or web2.
vded-rs-002 & vded-rs-003 are the 2 webservers but I don't know how to tell DNS that these 2 are part of the domain zone.
Here's the gmail response:
Delivered-To: xxxxxx@gmail.com
Received: by 10.220.75.17 with SMTP id w17cs41067vcj;
Thu, 27 Oct 2011 03:32:24 -0700 (PDT)
Received: by 10.216.90.4 with SMTP id d4mr1018977wef.22.13197115 43390;
Thu, 27 Oct 2011 03:32:23 -0700 (PDT)
Return-Path: <www-data@vded-rs-002.serv ers.wirehi ve.net>
Received: from vded-rs-002.servers.wirehi ve.net (vded-dc-002.servers.wireh ive.net. [91.227.26.58])
by mx.google.com with ESMTP id c1si3646971wed.98.2011.10. 27.03.32.2 2;
Thu, 27 Oct 2011 03:32:23 -0700 (PDT)
Received-SPF: pass (google.com: best guess record for domain of www-data@vded-rs-002.serve rs.wirehiv e.net designates 91.227.26.58 as permitted sender) client-ip=91.227.26.58;
Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of www-data@vded-rs-002.serve rs.wirehiv e.net designates 91.227.26.58 as permitted sender) smtp.mail=www-data@vded-rs -002.serve rs.wirehiv e.net
Received: by vded-rs-002.servers.wirehi ve.net (Postfix, from userid 33)
id 3398832085A; Thu, 27 Oct 2011 11:34:48 +0100 (BST)
To: xxxxxx@gmail.com
Subject: Account Activation
X-PHP-Originating-Script: 1001:signup_process.php
From: MyDomain Mailer <noreply@mydomain.com>
Message-Id: <20111027103448.3398832085 A@vded-dc- 002.server s.wirehive .net>
Date: Thu, 27 Oct 2011 11:34:48 +0100 (BST)
vded-rs-002 & vded-rs-003 are the 2 webservers but I don't know how to tell DNS that these 2 are part of the domain zone.
Here's the gmail response:
Delivered-To: xxxxxx@gmail.com
Received: by 10.220.75.17 with SMTP id w17cs41067vcj;
Thu, 27 Oct 2011 03:32:24 -0700 (PDT)
Received: by 10.216.90.4 with SMTP id d4mr1018977wef.22.13197115
Thu, 27 Oct 2011 03:32:23 -0700 (PDT)
Return-Path: <www-data@vded-rs-002.serv
Received: from vded-rs-002.servers.wirehi
by mx.google.com with ESMTP id c1si3646971wed.98.2011.10.
Thu, 27 Oct 2011 03:32:23 -0700 (PDT)
Received-SPF: pass (google.com: best guess record for domain of www-data@vded-rs-002.serve
Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of www-data@vded-rs-002.serve
Received: by vded-rs-002.servers.wirehi
id 3398832085A; Thu, 27 Oct 2011 11:34:48 +0100 (BST)
To: xxxxxx@gmail.com
Subject: Account Activation
X-PHP-Originating-Script: 1001:signup_process.php
From: MyDomain Mailer <noreply@mydomain.com>
Message-Id: <20111027103448.3398832085
Date: Thu, 27 Oct 2011 11:34:48 +0100 (BST)
As you can see the envelope-from is your webserver user@server, and the return-path is the same since setting return-path in the headers when sending it is not the correct practice as I mentioned.
Add the 5th argument to mail() to set the envelope-from as I suggested previously, test, and paste headers.
Add the 5th argument to mail() to set the envelope-from as I suggested previously, test, and paste headers.
envelope-from:
smtp.mail=www-data@vded-rs-002.servers.wirehive.net
Make sure the IP's of your webservers are in the SPF record for mydomain.com.
I've always used the \r\n line endings. Here are the headers I think I would use...
$headers = "From: myDomain Mailer <noreply@mydomain.com> \r\n";
// NOT $headers .= "To-Sender: \n";
// NOT $headers .= "X-Mailer: PHP\n"; // mailer
$headers .= "Reply-To: noreply@mydomain.com\r\n"; // Reply address
$headers .= "Return-Path: returns@mydomain.com\r\n"; //Return Path for errors
$headers .= "Content-Type: text/plain; charset=iso-8859-1"; // NOT SURE ABOUT THIS ONE...
$headers .= "\r\n\r\n";
You might also want to include some specific information like, "Hello Ray: Here is your account activation link for..."
$headers = "From: myDomain Mailer <noreply@mydomain.com> \r\n";
// NOT $headers .= "To-Sender: \n";
// NOT $headers .= "X-Mailer: PHP\n"; // mailer
$headers .= "Reply-To: noreply@mydomain.com\r\n";
$headers .= "Return-Path: returns@mydomain.com\r\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1"; // NOT SURE ABOUT THIS ONE...
$headers .= "\r\n\r\n";
You might also want to include some specific information like, "Hello Ray: Here is your account activation link for..."
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello,
I would suggest to avoid mail() function and send emails through SMTP with user/pass autentication and get rid of DNS and other annoying customizations.
In addition, I use this script for this purpose: http://phpmailer.worxware.com
Regards
Chorch
I would suggest to avoid mail() function and send emails through SMTP with user/pass autentication and get rid of DNS and other annoying customizations.
In addition, I use this script for this purpose: http://phpmailer.worxware.com
Regards
Chorch
Though 'phpmailer' may be a better or more complete email function, it will not solve any of the other problems mentioned here related to email getting blocked.
ASKER
Soz guys, will update shortly on tests...
If emails sent through SMTP are not being blocked (and this is the reason I begun to use PHPMailer, problem is solved, at least partially.
Even with DNS and LB correctly setup there can be hundreds of reasons of mails being blocked.
It should be checked rDNS, sender email exists, email contents, if one of the originating IP is somewhere blacklisted, etc etc etc.....
Even with DNS and LB correctly setup there can be hundreds of reasons of mails being blocked.
It should be checked rDNS, sender email exists, email contents, if one of the originating IP is somewhere blacklisted, etc etc etc.....
ASKER
Thanks for your help all, email is working good now - thanks to SPF and the mail() amendments.
Remove the Return-Path header as that is supposed to be added by the receiving server just before delivery. If you are trying to set the envelope-from, use the 5th argument in mail() to use -f with sendmail.
Open in new window