wp_mail returns true but not receiving mails

admin

Administrator
Staff member
I am using wp_mail() to receive mails which is submitted through a contact form in my wordpress blog. wp_mail() returns true but the thing is i am not receiving any mails. I have also tried to change the mail address to hotmail from gmail but no luck.

<strong>Ajax code in my contact template</strong>

Code:
$('#send').click(function() {
    //For Validation
    function validateText(name) {
        var pattern = /^[a-zA-Z'-.\s]+$/;
        if (pattern.test(name)) {
            return true;
        } 
        return false;
    }
    //For Validation
    function validateMail(mail) {
        var pattern = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,3}$/;
        //var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
        if (pattern.test(mail)) {
            return true;
        }     
        return false;
    }
    //Getting values from the form
    var name = $('#name').val(), mail = $('#mailid').val(), query = $('#message').val(), error = 1;
    //For Validation
    if(name == "" || !(validateText(name))) {
        $('#name').addClass('error');
        error = 0;
    }
    ////For Validation
    if(mail == "" || !(validateMail(mail))) {
        $('#mailid').addClass('error');
        error = 0;
    }
    //For Validation
    if(query == "") {
        $('#message').addClass('error');
        error = 0; 
    }
    if(!error) { // If validation fails
        return false;
    }

    $('#sendAlert').show();
        $('#send').html('Sending...');
        $.post(ajax_object.ajaxurl, { // Using ajax post method to send data
            action: 'ajax_action',
            sendmail: 'nothing',
            name: name,
            mail: mail,
            query: query
        }, function(data) {
            $('#send').html('Send');
            alert(data); // Alerting response
            return false;
        });

   });

<strong>In Functions.php</strong>

Code:
function ajax_action_stuff() {
if(isset($_POST['sendmail'])) {

    function set_html_content_type()
    {
    return 'text/html';
    }

    if(isset($_POST['name']) &amp;&amp; isset($_POST['mail']) &amp;&amp; isset($_POST['query'])) {  

    $name = $_POST['name'];
    $email = $_POST['mail'];
    $query = $_POST['query'];
    $to = '[email protected]';

    if($name == "" || $email == "" || $query == "") {
        echo "Fail";
        return false;
    }

    $subject = "Website - Query from ".$name;
    $message = "Hi,
        &lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt;:".$name."&lt;/p&gt;
        &lt;p&gt;&lt;strong&gt;Mail&lt;/strong&gt;:".$email."&lt;/p&gt;
        &lt;h3&gt;&lt;strong&gt;Query&lt;/h3&gt;
        &lt;p&gt;".$query."&lt;/p&gt;";
    $headers[] = 'From: [email protected]'."\r\n";
    $headers[] = '';

    add_filter( 'wp_mail_content_type', 'set_html_content_type' );
    $mailsent = wp_mail( $to, $subject, $message, $headers);
    remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); // reset content-type to to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578


    if($mailsent) {
        echo $to;
    } else {
        echo 'error';
    }
   } else {
    echo 'error';   
   }

 } else {
    echo 'error';
 }
 die();
   }
   add_action( 'wp_ajax_ajax_action', 'ajax_action_stuff' );
   add_action( 'wp_ajax_nopriv_ajax_action', 'ajax_action_stuff' );