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

Published by

Brian Gaeddert

A hard working quick learner who is an ambitious and self-motivated web developer with a strong technical and design background who possesses self-discipline and the ability to work with the minimum of supervision. A great team player who thrives on creating innovative solutions in a multidisciplinary team, is detail-oriented and has the ability to produce detailed technical specifications from client requirements. A quick learner who can absorb new ideas and communicate quickly and effectively. A high awareness of industry issues and trends, particularly in regard to emerging technologies, website usability/accessibility, mobile solutions, and data integration. Native English speaker with professional proficiency in Spanish.

Leave a Reply

Your email address will not be published. Required fields are marked *