This is not spam! GMAIL

Question:

When using Media Temple Virtual Dedicated (dv) server – Why does gmail think all email is being sent using PHP mail() is being sent from the primary domain and not other domains host on the same server. Why is google receiving emails that say: Username <username@secondarydomain.com> via primarydomain.com.  I want to get rid of the darn via!

Answer:

In the gmail help it says you need to sent up SPF and Domainkeys. I set up the SPF and tried again and the email was being authenticated but by the primary domain not the secondary.

I stuggled with this for days, then I relized that when mail was sent by the webmail client on the secondary server it arrived at gmail just fine. So it dawned on me to compare the two email headers.

This can be done by opening the email and next to the reply button is a drop down where you click “Show original”. This will show the message as gmail received it. What I notice was the problem emails had:

     Return-Path<anonymous@primarydomain.com>

And the emails from the secondary domains webmail client had

     Return-Path: <username@secondarydomain.com>

When you call mail() in PHP it just calls sendmail on the server and if you don’t tell it the return path it will use anonymous@primarydomain.com by default. Use the code below as a template to send non-spam emails to gmail.

PHP code:

$to = 'recipient@email.com';
	
$message = 'This is a test email';
	
// subject
$subject = 'Sample Email';
	
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
$headers .= 'From: Pupalup ' . PHP_EOL;
$headers .= 'Reply-To: noreply@example.com' . PHP_EOL;
$headers .= 'Return-path: noreply@example.com' . PHP_EOL;
$headers .= 'X-Mailer: PHP/' . phpversion();
	
// Mail it
mail($to, $subject, $message, $headers);