ARH3 ARH3 - 3 months ago 11
PHP Question

PHP mail() function will not send to gmail but will send to my non-gmail account

For some reason the php mail() function is not working properly on a site I am building. I tried to troubleshoot the issue down to its simplest form, and came up with this file:

<?php
mail('myEmail@gmail.com', 'the subject', 'the message', 'From: webmaster@example.com', '-fwebmaster@example.com');
?>


when myEmail is a gmail account, I never recieve the message. However when I use a non-gmail account, I do recieve the message. I am at a loss and have tried everything to figure this out. I am starting to think it is an obscure host/server issue. You can see the server specs here: http://aopmfg.com/php.php

Any ideas?

EDIT - let me also add that this was all working fine a few weeks ago, the last time I tested it. No significant code changes since then at all.

EDIT 2 - After reading a similar post I tried adding From and Reply-To headers... still no luck. New code:

<?
$headers = 'From: <some@email.com>' . "\r\n" .
'Reply-To: <some@email.com>';

mail('<myEmail@gmail.com>', 'the subject', 'the message', $headers,
'-fwebmaster@example.com');
?>

Answer

It turns out that Google blocked my server because another site on the same server was hacked and used for spam.

To test and ensure that it was a problem with the server, I created a simple PHP file that would send an email to my email address on page refresh. It worked when I sent to my exchange-based email address, but not to any Google-related accounts.

Code:

$headers = 'From: <test@test.com>' . "\r\n" .
'Reply-To: <test@test.com>';

mail('<myEmail@gmail.com>', 'the subject', 'the message', $headers,
  '-fwebmaster@example.com');
?>

Thanks for the help all.

Comments