wp_mail() is not working in localhost

by user2728494   Last Updated July 28, 2015 13:03 PM

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 = "[email protected]";
    $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.



Answers 1


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.

David
David
July 28, 2015 07:38 AM

Related Questions




wp_mail() not working but respons shows true

Updated March 02, 2017 11:08 AM

how to insert data by form in database

Updated March 23, 2016 08:03 AM

An old plugin self-made stoped sending mail.

Updated September 07, 2017 14:08 PM