php contact form was not working and not redirecting to success page

70 Views Asked by At

whats wrong in my code?

In HTML, I have taken form and i have created heading3 and i taken two inputs for name and email and i written textarea for message at last i taken another input is for submit and i closed the form tag.

<form method="post" action="contactengine.php">
  <h3>Message Me</h3>
  <input type="text" name="Name" id="Name" placeholder="Enter Name" required>
  <input type="email" name="Email" id="Email" placeholder="Enter Email" required>
  <textarea name="Message" id="Message" placeholder="Your Message">   </textarea>
  <input type="submit" name="submit" value="Send Now" class="submit-button">
</form>
<?php

$EmailFrom = "[email protected]";   //your first email from where you want to send email
$EmailTo = "[email protected]";   //your second email where you want to receive contact form content
$Subject = $_POST['Name']." Contacted you from your portfolio site";  //mail subject
$Name = Trim(stripslashes($_POST['Name']));    //getting name from html page
$Email = Trim(stripslashes($_POST['Email']));     //getting email from html page
$Message = Trim(stripslashes($_POST['Message']));     //getting message from html page

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
1

There are 1 best solutions below

0
On

I would try this:

// send email 
$success = mail($EmailTo, $Subject, $Body, "From:" . $EmailFrom);