0

My PHP form is not working correctly, I am getting 'failed' message when I press the 'Submit' button. That code was working before 4 or 5 months, but now it is not working. I think my code is correct, but I don't know why I am getting 'failed' message.

<?php

$subject = 'You Got Message'; // Subject of your email
$to = 'info@springwater.uz';  //Recipient's E-mail
$emailTo = $_REQUEST['email'];

$name = $_REQUEST['username'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$sb = $_REQUEST['subject'];
$product = $_REQUEST['product'];
$quantity = $_REQUEST['number'];
$msg = $_REQUEST['message'];

$email_from = $name.'<'.$email.'>';

$headers = "MIME-Version: 1.1";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$headers .= "From: ".$name.'<'.$email.'>'."\r\n"; // Sender's E-mail
$headers .= "Return-Path:"."From:" . $email;

$message .= 'Name : ' . $name . "\n";
$message .= 'Email : ' . $email . "\n";
$message .= 'Phone : ' . $phone . "\n";
$message .= 'Subject:' .$sb . "\n";
$message .= 'Product:' .$product . "\n";
$message .= 'Quantity:' .$quantity . "\n";
$message .= 'Message : ' . $msg;

if (@mail($to, $subject, $message, $email_from))
{
    // Transfer the value 'sent' to ajax function for showing success message.
    echo "<script> location.href='index.html'; </script>";
}
else
{
    // Transfer the value 'failed' to ajax function for showing error message.
    echo 'failed';
}
?>

I've tried to create contact form in order to get email from clients. But this form is not working. After pressing submit butter, I am getting 'failed'.

  • 2
    Step 1: STOP suppressing errors with the `@` operator! (And enable proper PHP error reporting, if you have not done so yet.) – CBroe Sep 09 '22 at 13:19
  • 1
    `$headers .= "From: ".$name.'<'.$email.'>'."\r\n"; // Sender's E-mail`- wrong, wrong, ultra mega wrong; see https://stackoverflow.com/a/24644450/1427878, "Don't use a faux From: sender" – CBroe Sep 09 '22 at 13:21

0 Answers0