wp_mail() is not working in localhost

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.

2 Answers
2

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.

Leave a Comment