-1

I'm using the below code to send mail. Only the User who submits the form receives mail but not the admin.

I have tried with "$mail_to = "admin@sampledemos.online";" and include the same in mail function () and also included the mail address directly in the mail function as "mail($email_from, $mail_title, $mail_body, $headers, "admin@sampledemos.online") )", but still admin didn't receive any mail so far.

    $headers = "From: $email_from\nMIME-Version: 1.0\nContent-type: text/html; charset=iso-8859-1\n";
    $mail_to = "admin@sampledemos.online";
    if( mail($email_from, $mail_title, $mail_body, $headers, "admin@sampledemos.online") ) {
        $serialized_data = '{"type":1, "message":"Contact form successfully submitted. Thank you, I will get back to you soon!"}';
        echo $serialized_data;
    } else {
        $serialized_data = '{"type":0, "message":"Contact form failed. Please send again later!"}';
        echo $serialized_data;
    }
};
3iL
  • 2,146
  • 2
  • 23
  • 47
Hari
  • 7
  • 3
  • Please [read the manual](https://www.php.net/manual/en/function.mail.php) carefully if this is using the standard PHP `mail()` function. If it isn't you should tell us more about it. – KIKO Software Jul 22 '19 at 09:27
  • `mail()` is so fiddly and unreliable, you would be much better off using PHPMailer or SwiftMailer. They will give you much more control over mail sending. – halfer Jul 22 '19 at 10:19

1 Answers1

-1

The below code works for me....

$to = "test123@gmail.com";
$subject = "Contact Form Message";
if( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message']) ){
    $header = "From: $email_from\nMIME-Version: 1.0\nContent-type: text/html; charset=iso-8859-1\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-type: text/html\r\n";

    $retval = mail ($to,$subject,$message,$header);

         if( $retval == true ) {
            $serialized_data = '{"type":1, "message":"Contact form successfully submitted. Thank you, We will will get back to you soon!"}';
        echo $serialized_data;
         }else {
            $serialized_data = '{"type":0, "message":"Contact form failed. Please send again later!"}';
        echo $serialized_data;
         }
};
Hari
  • 7
  • 3