[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

PHP mailout and spam filters

Hi all,

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);

Open in new window


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.wirehive.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
0
dolythgoe
Asked:
dolythgoe
  • 7
  • 5
  • 2
  • +2
1 Solution
 
PapertripCommented:
Please post the headers from the mail sent to your gmail.


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.

mail($email, $subject, $message, $headers, '-freturns@mydomain.com');

Open in new window

0
 
Ray PaseurCommented:
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.
0
 
dolythgoeAuthor Commented:
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?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
PapertripCommented:
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.
0
 
Dave BaldwinFixer of ProblemsCommented:
I thought the headers required '\r\n', not just '\n'.  http://tools.ietf.org/html/rfc5322#section-2.2
0
 
PapertripCommented:
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 :)
0
 
dolythgoeAuthor Commented:
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.1319711543390;
        Thu, 27 Oct 2011 03:32:23 -0700 (PDT)
Return-Path: <www-data@vded-rs-002.servers.wirehive.net>
Received: from vded-rs-002.servers.wirehive.net (vded-dc-002.servers.wirehive.net. [91.227.26.58])
        by mx.google.com with ESMTP id c1si3646971wed.98.2011.10.27.03.32.22;
        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.servers.wirehive.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.servers.wirehive.net designates 91.227.26.58 as permitted sender) smtp.mail=www-data@vded-rs-002.servers.wirehive.net
Received: by vded-rs-002.servers.wirehive.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.3398832085A@vded-dc-002.servers.wirehive.net>
Date: Thu, 27 Oct 2011 11:34:48 +0100 (BST)



0
 
PapertripCommented:
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.
0
 
PapertripCommented:
envelope-from:
smtp.mail=www-data@vded-rs-002.servers.wirehive.net

Open in new window

0
 
PapertripCommented:
Make sure the IP's of your webservers are in the SPF record for mydomain.com.
0
 
Ray PaseurCommented:
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..."
0
 
dolythgoeAuthor Commented:
Will do - just reading up on SPF - the DNS bit I'm finding hard to get my head round at the mo!! Will do a test when I think I've managed it. My DNS system seems strange compared to what I'm used to - always has the domain after a textbox:

dns web control panel
0
 
PapertripCommented:
I'm not familiar with that specific interface, but here is what you should put.

Name - leave blank
Type - TXT
Content - "v=spf1 ip4:1.2.3.4 ip4:1.2.3.5 -all"
Priority - leave blank
TTL - 3600

The example record I used assumes your sending IP's are 1.2.3.4 and 1.2.3.5, so change those to your webserver IP's and make sure any other sending servers for your domain are included as well.

Make sure you don't already have an SPF record, as you can only have 1.
0
 
ChorchCommented:
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
0
 
Dave BaldwinFixer of ProblemsCommented:
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.
0
 
dolythgoeAuthor Commented:
Soz guys, will update shortly on tests...
0
 
ChorchCommented:
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.....
0
 
dolythgoeAuthor Commented:
Thanks for your help all, email is working good now - thanks to SPF and the mail() amendments.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 7
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now