I am making a website in which I create an HTML contact us form and using I am using PHP to send mail for that form. Mail sending doesn't work But I used the same code for another website below fine for one website but not for another one. according to me, problem is in this line mail($to,$email_subject,$email_body,$headers);
What I have tried:
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "fill the textboxes";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'my@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "noreply@gmail.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address";
$mail_result = mail($to,$email_subject,$email_body,$headers);
if($mail_result)
{
echo "send";
}
else
{
echo "failed";
}
?>