Why wp_mail() function returns 'false'?


I have a contact form that gets from ajax parameters and uses them to send emails. The function is located in functions.php of my child theme for twentyfifteen:

// Contact form  Ajax 

add_action('wp_ajax_nopriv_submit_contact_form', 'submit_contact_form'); 

function submit_contact_form(){

    if(isset($_POST['email'])) {

        $email = $_POST['email'];       
        $email_to = "[email protected]";

        $email_subject = "You have a new email from $email via yyy.com website";
        $message = $_POST['text']; 

        if( wp_mail( $email_to, $email_subject, $message ) ) {
            // the message was sent...
            echo 'The test message was sent. Check your email inbox.';
        } else {
            // the message was not sent...
            echo 'The message was not sent!';

//      wp_mail( $email_to, $email_subject, $message );
        header("Content-Type: application/json", true);
        echo json_encode( array("AJAX" => "Success") );


ini_set("display_errors", 1);

I'm getting a response of the message was not sent! AJAX: "Success".

Why my function isn't working? Do I have to include something in my php file? I var_dumped the parameters that I get from ajax, the are all displayed fine in the response with a status code of Status Code:200 OK.


I installed a package called "PostFix" which is responsible for sending emails from an Ubuntu server (which is the servers Linux I use), and it solved the problem!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment