I have these exact same PHP contact form codes on 2 different servers. 1 is working as intended, but the other is returning the error message instead of the success message. Also, email is not sent to me.
Contact.php codes as follows:
<?php
ob_start();
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$query = $_POST['message'];
$email_from = $name.'<'.$email.'>';
$to="[email protected]";
$subject="Enquiry";
// $headers = 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$email_from."\r\n";
$message="
Name:
$name
Email:
$email
Message:
$query
";
if(mail($to,$subject,$message,$headers))
header("Location: http://www.website.com/contact.php?msg=Successful Submission! Thank you for contacting us.");
else
header("Location: http://www.website.com/contact.php?msg=Error Sending Email!");
}
?>
I'm wondering if it is permissions/server problem? Any help will be greatly appreciated! Thanks!
Your code construct is correct, and the return value (which is your custom error) might be correct "if" the mail function is failing.
A lot of time we find php mail() function is not working. In some cases, the email is not sent even the function returns true. Following are the points you may check while debugging:
If you have access check your mail log file to see if the email is blocked by the mail server or have not reached the server yet. If there is no entry of your email in the log, it means you have problem in your php code or php configuration. If it is in the log, you can see why it was not delivered. The typical path to mail log file is /var/log/maillog