Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to use wp_mail (testing on local machine) but no mail is received. The php.ini has smtp_port = 25 set and the php mail() is working so far.

  • how can I check if wp_mail is working
  • what can fail

Here is the code of my mail function:

function mv_optin_mail($id, $data){

    $url = $id."-".mv_mail_token($id, $data['token']);

    add_filter( 'wp_mail_content_type', 'set_html_content_type' );
    add_filter( 'wp_mail_charset', 'utf8' );

    $headers[] = 'From: '.sender_signature.' <'.noreply_address.'>';    

    $html_mail = ob_get_contents();

    wp_mail( $data['email'], 'Some Subject', $html_mail, $headers );
    remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
    remove_filter( 'wp_mail_charset', 'utf8' );

I don't get any errors. Is there a way to toggle error-loggin for wordpress?

The noreply_address is noreply@root

share|improve this question
Now the remaining questions are: What is mv_mail_token() and what does it return and where does the constant sender_signature come from and what does it contain? – kaiser Jun 23 '13 at 18:01
Kaiser, listen, please try to answer the questions ... wp_mail_token() returns a string and sender_signature does at well. – helle Jun 24 '13 at 8:38
debug gist – kaiser Jun 24 '13 at 9:02

3 Answers 3

I would start by enabling WP_DEBUG in wp-config and see if that shows you anything about your code or the code for the wp_mail function. That is about it for debugging right out of the box with WP.

Also, you can use Easy WP SMTP and enable debugging and/or set that up to use SMTP. There are similar plugins on but I know this one has a good debug option. If something like GMail works then you'll know it is a server setting and not this code.

share|improve this answer

What I usually do to test if wp_mail() is sending e-mails properly is just registering on my website with another e-mail address and seeing if the e-mail arrives. If it does, it means that WordPress is properly sending e-mails (it uses wp_mail() to send registration e-mails) and you should inspect your mail sending function for any errors. To do that, as @Tobias suggested, you should strip everything from your mail sending function and only leave the basic:

function wpse_100047() {
    echo wp_mail( '', 'WP Mail Test', 'Mail is working' );

Additionally, the e-mails sent by WordPress (as all e-mails sent by PHP's mail() function might be blocked by some e-mail servers (or marked as spam) so it's always a good idea to use SMTP (multiple plugins that do that) for e-mails on the live website.

share|improve this answer

Wordpress relies on the PHPMailer class to send email through PHP's mail function.

Since PHP's mail function returns very little information after execution (only TRUE or FALSE), I suggest temporarily stripping down your mv_optin_mail function to a minimum in order to see if the wp_mail functions works.


$mailResult = false;
$mailResult = wp_mail( '', 'test if mail works', 'hurray' );
echo $mailResult;

Since you've tested PHP's mail function already, the mail should arrive.

If it does not, the problem lies in the other statements of your function or in the PHPMailer class.

In cases like this, I usually rename my function to something like:

function mv_optin_mail_backup( $id, $data ) {

And add a temporary function with the same name to mess around with like so:

function mv_optin_mail( $id, $data ) {
    $mailResult = false;
    $mailResult = wp_mail( '', 'test if mail works', 'hurray' );
    echo $mailResult;

When I have figured out what the problem is, I start using the backup version again.

To send a mail using PHPMailer directly you can do something like this (not for production, just for debugging):

add_action( 'phpmailer_init', 'my_phpmailer_example' );
function my_phpmailer_example( $phpmailer ) {
    //$phpmailer->Host = '';
    //    $phpmailer->SMTPAuth = true; // Force it to use Username and Password to authenticate
    $phpmailer->Port = 25;
    //    $phpmailer->Username = 'yourusername';
    //    $phpmailer->Password = 'yourpassword';

    // Additional settings…
    //$phpmailer->SMTPSecure = "tls"; // Choose SSL or TLS, if necessary for your server
    $phpmailer->setFrom( "", "From Name" );
    $phpmailer->addAddress( "", "Your name" );
    $phpmailer->Subject    = "Testing PHPMailer";           
    $phpmailer->Body     = "Hurray! \n\n Great.";
    if( !$phpmailer->send() ) {
        echo "Mailer Error: " . $phpmailer->ErrorInfo;
    } else {
        echo "Message sent!";

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.