0

I tried to send email using php mail() function. It is sending to @mydomain email id,but it is not sending to @gmail and @hotmail. It shows the message "failed" (see the code below)

<?php


if($_POST['name'])
{
    $subject = "Message from website";

    $name = $_POST['name'];
    $email = $_POST['email'];
    $number = $_POST['number'];
    $to = 'xxx@gmail.com';

    $txt = " Name : " . $name . " \r\n Email : " . $email . " \r\n Contact No. : " . $number;

    $mail = mail($to, $subject, $txt, "From: ".$name." <".$email.">\r\n"."Reply-To: ".$email."\r\n"."X-Mailer: PHP/" . phpversion());

    if($mail)
    {
        echo "Thank You!";

    }

    if(!$mail)
    {
        echo "failed";//print_r(error_get_last());
    }
}
else
    echo "no values entered";
?>

When I send it to @gmail or hotmail address it shows the message "failed".

If I add print_r(error_get_last()) instead of 'echo "failed"', it shows blank

I googled for answers,but no luck. Many answers related are years old. I hope someone help me.

Thanks in advance

Abdulla
  • 441
  • 1
  • 9
  • 21

0 Answers0