2

I'm trying to test wp_mail() in my local. When I var dump wp_mail,I get Boolean false.This is my code

    $to = "abcd@gmail.com";
    $subject = 'my subject';
    $message = 'I would like to work with you';
    $headers = '';


    $sent_message = wp_mail( $to, $subject, $message, $headers);
    var_dump($sent_message); // i get boolean false here.
    if ( $sent_message ) {
        echo 'The test message was sent. Check your email inbox.';
    } else {
        echo 'The message was not sent!'; //this gets printed in d end.
    }

Any help would be appreciated.

4

wp_mail() falls back to php's mail() function which requires a configured MTA (Message Transfer Agent) on your host. So either you install and configure such a MTA. If you're running a Linux like OS, SSMTP is an easy solution on which you can use any mail-provider to send your system mails via SMTP. Another MTA would be Sendmail, a full featured, yet difficult to configure MTA.

Or you simply use a plugin like WP Mail SMTP which implements a direct SMTP connection in PHP and bypass the mail() usage.

  • If you just want to test mail functionality while developing you can use mailcatcher: mailcatcher.me Didn't test it on windows - but on Mac os it running. On other linux os it should work as well. – Luckyfella Aug 24 '17 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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