None of my Wordpress emails are sent to Gmail. More info:
EXIM logs say that the email is sent succesfully to Gmail, but they are not sent, or sent in spam.
The problem is a combination of factors:
Sender
headerSender
header, it will most likely silently discard it, or send it as spam.Sender
headerOnce you know these, the fix is quite simple. If you are using Wordpress, the quick and dirty way to do it is to go to wp-includes/pluggable.php
, look for the wp_mail()
function search for:
$phpmailer->From = apply_filters( 'wp_mail_from' , $from_email );
then add the following right after it:
$phpmailer->Sender = $phpmailer->From;
Once you do this, emails will work, and you can fix the problem the proper way, without overwriting the core, by writing a plugin. Wordpress uses phpmailer which knows about this issue, but wordpress doesn't use it. There is also a bug report on this issue.
To fix the problem using the core mail() function, you have to do the following:
// $sender can be the same email address as the From header
mail($to, $subject, $message, $additional_headers, "-f {$sender}")
There is another option that may work, depending on the configuration of your server (I couldn't test it, would love if someone could test this):
$sendmailFrom = ini_get('sendmail_path');
ini_set('sendmail_path', $sendmailFrom . ' -f sender@mysite.com'); // or whatever you want