This question already has an answer here:
The php form is throwing the error handling message and I couldn't find what is the issue. I tried to remove the validations but I keep ending up with the same problem.
The error message I recieve is "We are sorry but the email did not go through." meaning that the php starts handling the form but maybe there's an issue with mail function parsing.
<div class="row"><div class="span8"><h4>تواصل معنا بتعبئة النموذج التالي</h4><div id="sendmessage">تم إرسال الرسالة بنجاح</div><div id="errormessage"></div><form action="contactform.php" method="post" role="form" class="contactForm"><div class="row"><div class="span4 form-group field"><input type="text" name="visitor_name" id="name" placeholder="اللإسم" data-rule="minlen:4" data-msg="الرجاء إدخال الإسم كامل" /><div class="validation"></div></div><div class="span4 form-group"><input type="email" name="visitor_email" id="email" placeholder="البريد الإلكتروني" data-rule="email" data-msg="الرجاء إدخال بريد إلكتروني صالح" /><div class="validation"></div></div><div class="span8 form-group"><input type="text" name="email_title" id="subject" placeholder="الموضوع" data-rule="minlen:4" data-msg="الرجاء إدخال 8 أحرف على الأقل في الموضوع" /><div class="validation"></div></div><div class="span8 form-group"><textarea name="visitor_message" rows="5" data-rule="required" data-msg="الرجاء كتابة محتوى الرسالة"
placeholder="الرسالة"></textarea><div class="validation"></div><div class="text-center"><button class="btn btn-theme btn-medium margintop10" type="submit" value="submit">إرسال البريد</button></div></div></div></form></div>
<?php
if($_POST) {
$visitor_name = "";
$visitor_email = "";
$email_title = "";
$visitor_message = "";
if(isset($_POST['visitor_name'])) {
$visitor_name = filter_var($_POST['visitor_name'], FILTER_SANITIZE_STRING);
}
if(isset($_POST['visitor_email'])) {
$visitor_email = str_replace(array("\r", "\n", "%0a", "%0d"), '', $_POST['visitor_email']);
$visitor_email = filter_var($visitor_email, FILTER_VALIDATE_EMAIL);
}
if(isset($_POST['email_title'])) {
$email_title = filter_var($_POST['email_title'], FILTER_SANITIZE_STRING);
}
if(isset($_POST['visitor_message'])) {
$visitor_message = htmlspecialchars($_POST['visitor_message']);
}
else {
$recipient = "info@domain.ly";
}
$headers = 'MIME-Version: 1.0' . "\r\n"
.'Content-type: text/html; charset=utf-8' . "\r\n"
.'From: ' . $visitor_email . "\r\n";
if(mail($recipient, $email_title, $visitor_message, $headers)) {
echo "<p>Thank you for contacting us, $visitor_name. You will get a reply within 24 hours.</p>";
} else {
echo '<p>We are sorry but the email did not go through.</p>';
}
} else {
echo '<p>Something went wrong</p>';
}
?>