Hi guys I am developing a site and am producing an email form using php, I had various issues before such as " failed to connect to mailserver at "local host" port 25. Verify SMTP etc." so as a result a potential solution was to make the site online, therefore I have and the php code is inserted in the live site and the error did disappear however no mail was sent to email address listed. I have been working on this form for about a week now and tried out various different forms which are available on the internet but still no email received. My php code is below:
UPDATED PHP CODE
<?php
//Checks for header injection
function has_header_injection($str){
return preg_match("/[\r\n]/",$str);
}
if(isset($_POST['contact_submit'])){
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$msg = $_POST['message'];
//check to see if name or email have header injecion
if(has_header_injection($name) || has_header_injection ($email)){
die(); //if true kill script
}
if(!$name || !$email || !$msg){
echo '<h4 class = "error"> All fields are required </h4> <a href = "contact.php" class = "button block"> Go Bacck and Try again </a>';
exit;
}
//add recipient email to variable
$to = "mahdi.mashrafi@yahoo.com";
$subject = "$name sent you a message via your contact form";
$message = "Name: $name\r\n";
$message .= "Email: $email\r\n";
$message .= "Message:\r\n$msg";
$message = wordwrap($message, 72);
//set mail headers into a variable
$headers = "MIME-Version: 1.0\r\n";
$headers .="Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email> \r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority:High\r\n\r\n";
$status = mail ($to, $subject , $message , $headers);
var_dump($status);
?>
**HTML FORM**
<h5>Thanks for contacting </h5>
<p>Please allow 24 housr to respond</p>
<p> <a href = "/final" class = "bitton block">« Go to homepage </a> </p>
<?php } else {?>
<form method = "post" action = "" id = "contact-form">
<label for = "name">Your name </label>
<input type = "text" id = "name" name = "name">
<label for = "email">Your email</label>
<input type = "email" id = "email" name = "email">
<label for = "message">and your message </label>
<textarea type = "message" id = "message" name = "message"></textarea>
<input type = "submit" class = "button next" name = "contact_submit" value ="Send Message">
</form>
<?php } ?>
</div>
Any good tutorials on email form will be great and potential solutions will also be hugely appreciated. I have literally no idea why the mail isnt being sent/recieved.
--------UPDATED THE PHP CODE HAS BEEN UPDATED -------