This is not spam! GMAIL


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 <> via  I want to get rid of the darn via!


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:


And the emails from the secondary domains webmail client had

     Return-Path: <>

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 by default. Use the code below as a template to send non-spam emails to gmail.

PHP code:

$to = '';
$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:' . PHP_EOL;
$headers .= 'Return-path:' . PHP_EOL;
$headers .= 'X-Mailer: PHP/' . phpversion();
// Mail it
mail($to, $subject, $message, $headers);