Mail problem
Posted: Thu Jan 29, 2015 2:15 pm
I have designed a contact page everything seems to be work except that the email isn't getting through to the intend recipient. The sent mail logs show that the email was sent from the form, but the email is never received. I have used this same form for other websites, but for this one site I have having problems. Am I missing something or is the issue with the host site or some other problem? Here is the code I am using.
I would appreciate any help. Thank you.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD Xhtml 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http=equiv="Content-Type" Content="text/html; charset=utf-8"/>
<title>Email Handle</title>
<style type="text/css" media="screen">
.error { color: red; }
</style>
</head>
<body>
<?php // Script 1.0 - email_handle.php
// Adjust for HTML tags:
$html_post = htmlentities($_POST['message']);
$strip_post = strip_tags($_POST['message']);
// Get the values from the $_POST array
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Flag variable to track success:
$okay = TRUE;
// Validate the name:
if (empty($_POST['name'])) {
print '<p class="error">Please enter your name.</p>';
$okay = FALSE;
}
// Validate the email address:
if (empty($_POST['email'])) {
print '<p class="error">Please enter your email address.</p>';
$okay = FALSE;
}
// Validate the Phone:
if (empty($_POST['phone'])) {
print '<p class="error">Please enter your email address.</p>';
$okay = FALSE;
}
// Validate email address format:
if (empty($_POST['email']) || (substr_count($_POST['email'], '@') != 1) ) {
print '<p class="error">Please enter a valid email address.</p>';
$okay = FALSE;
}
if ($okay) {
print '<p>Thank you for your inquiry.</p>
<p>Someone will respond to your inquire as soon as possible.</p>';
}
// Make a link to another page:
$name = urlencode($name);
$email = urlencode($_POST['email']);
print "<p>Click <a href=\"index.html\">here</a> to return to the homepage.</p>";
// Send the mail
if ($_POST["email"]<>'') {
$ToEmail = 'email@somewhere.ca';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Phone: ".$_POST["phone"]."";
$MESSAGE_BODY .= "Message: ".nl2br($_POST["message"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
}
?>