WordPress emails were not being sent out by the server. But why?
In this case the site is hosted by Goneo.
As it appears Goneo requires:
- Emails to be sent from an address registered with them
- The ‘Envelope-From’ email header set to that address
It’s not a bug, it’s a feature!
Set the thing…
WordPress sends its emails via the wp_mail() function. In turn, this function uses the PHPMailer library to generate and send the actual email. Just before sending the mail, wp_mail() calls the helpful phpmailer_init action which gives us access to the PHPMailer instance. This is where we can use the setfrom() method to set the Envelope From header:
add_action( 'phpmailer_init', 'prefix_add_phpmailer_setfrom' );
/**
* Add setFrom for hosts that insist on making life hard.
*
* @param array $phpmailer The PHPMailer instance, passed by reference.
*/
function prefix_add_phpmailer_setfrom( $phpmailer ) {
$phpmailer->setFrom(
get_option( 'admin_email' ), // From email address.
'WordPress' // From name.
);
}
Rejoice!
In phpmailler, the setFrom method sets the from e-mail not the envelope from.
To set envelope from, you need to set $Sender :
$phpmailer->Sender = ’[email protected]’;
While this works with phpmailler (not the wordpress one), the line above does not work when I replace it in your code.