PHP mail function does not send email if the domain is Gmail.com
I was testing my email form when I found out that if the email address was @gmail.com, the PHP mail() function failed.
Here's the scenario:
A visitor on my site wants to send me a message
He/She goes to the contact page and enters the email address @Gmail.com domain.
The PHP mail() script fails to deliver the message
To easiest way to resolve this issue is to change the from address in the headers to the match the domain name of the website. You can still use the gmail address in the reply-to field.
My modified headers were:
$replyto = 'firstname.lastname@example.org';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $sender . "\r\n" .
'Reply-To: ' . $replyto . "\r\n" .
'X-Mailer: PHP/' . phpversion();
I hope this helps