Mail function is not working

My mail function is not working. When I submit form it says mail sent. But not receiving. I tried echo if the mail sent. It is also working. What is the issue here? Anything with mail function ?

<?php
$name    = $_POST[ 'cuf_sender' . $n ];
$email   = $_POST[ 'cuf_email' . $n ];
$subject = $this->o['subpre'] . ' ' . $_POST[ 'cuf_subject' . $n ];
$msg     = $_POST[ 'cuf_msg' . $n ];

$extra = '';
foreach ( $_POST as $k => $f ) {
    if ( strpos( $k, 'cuf_field_' ) !== false ) {
        $extra .= $this->o[ substr( $k, 4, 7 ) ] . ": $frn";
    }
}

$headers =
    "MIME-Version: 1.0rn" .
    "Reply-To: "$name" <$email>rn" .
    "Content-Type: text/plain; charset="" . get_settings( 'blog_charset' ) . ""rn";
if ( ! empty( $from ) ) {
    $headers .= "From: " . get_bloginfo( 'name' ) . " - $name <$from>rn";
} else if ( ! empty( $email ) ) {
    $headers .= "From: " . get_bloginfo( 'name' ) . " - $name <$email>rn";
}

$fullmsg =
    "Name: $namern" .
    "Email: $emailrn" .
    $extra . "rn" .
    'Subject: ' . $_POST[ 'cuf_subject' . $n ] . "rnrn" .
    wordwrap( $msg, 76, "rn" ) . "rnrn" .
    'Referer: ' . $_SERVER['HTTP_REFERER'] . "rn" .
    'Browser: ' . $_SERVER['HTTP_USER_AGENT'] . "rn";

if ( wp_mail( $to, $subject, $fullmsg, $headers, $email ) ) {
    echo $to;
    exit();

Related posts

Leave a Reply

2 comments

  1. You are passing $email where there should be attachments. Look at wp_mail arguments.

    Also you have not defined $to variable which in your case i assume should be $email.

    Try this,

    $name   = $_POST['cuf_sender'.$n];
        $email  = $_POST['cuf_email'.$n];
        $subject= $this->o['subpre'].' '.$_POST['cuf_subject'.$n];
        $msg    = $_POST['cuf_msg'.$n];
    
        $extra = '';
        foreach ($_POST as $k => $f )
            if ( strpos( $k, 'cuf_field_') !== false )
                $extra .= $this->o[substr($k, 4, 7)].": $frn";
    
    
        $headers =
        "MIME-Version: 1.0rn".
        "Reply-To: "$name" <$email>rn".
        "Content-Type: text/plain; charset="".get_settings('blog_charset').""rn";
        if ( !empty($from) )
            $headers .= "From: ".get_bloginfo('name')." - $name <$from>rn";
        else if ( !empty($email) )
            $headers .= "From: ".get_bloginfo('name')." - $name <$email>rn";
    
        $fullmsg =
        "Name: $namern".
        "Email: $emailrn".
        $extra."rn".
        'Subject: '.$_POST['cuf_subject'.$n]."rnrn".
        wordwrap($msg, 76, "rn")."rnrn".
        'Referer: '.$_SERVER['HTTP_REFERER']."rn".
        'Browser: '.$_SERVER['HTTP_USER_AGENT']."rn";
    
        if ( wp_mail( $email, $subject, $fullmsg, $headers) )
        {
            echo $to;
        exit();
    
  2. In addition to the other suggestions, make sure that the ‘from’ email address is an email address that belongs to the domain of your site, and that it exists.

    Some hosts will not send mail from the example.com domain when the ‘from’ address is ‘someone@notmydomain.com’. They will sense that as a ‘mail relay’, which is what spammers will try, so will block the mail.

    Note that the return value of the mail() function is just a flag that shows that the message was successfully/unsuccessfully sent to the mail server. It is not an indication that the mail was actually sent.