(Please, if one more person on an Internet forum cyber-yells at me or calls me an idiot today, I'm going to really start crying, so just know that, before we start. In fact, it's already too late; I'm already crying. Support forums make me nervous.)
I have a simple contact form:
<form action="send_form_email.php" method="post">
<div class="clear">
</div>
<label>First Name:</label>
<INPUT class="textbox left " type="text" name="first_name" value="">
<div class="clear">
</div>
<label>Last Name:</label>
<INPUT class="textbox left " type="text" name="last_name" value="">
<div class="clear">
</div>
<label >E-Mail:</label>
<INPUT class="textbox left" type="text" name="email" value="">
<div class="clear">
</div>
<label >Phone Number:</label>
<INPUT class="textbox left" type="text" name="telephone" value="">
<div class="clear">
</div>
<label >Message:</label>
<TEXTAREA class="textbox left" name="comments" ROWS="5" COLS="25"></TEXTAREA>
<div class="clear">
</div>
<INPUT class="pin" type="submit" name="submit" value="submit">
</form>
This is my PHP form (send_form_email.php):
<?php
function isValidEmail($address)
{
if (filter_var($address, FILTER_VALIDATE_EMAIL) == FALSE)
return false;
/* explode out local and domain */
list($local, $domain) = explode('@', $address);
$localLength = strlen($local);
$domainLength = strlen($domain);
return ( /* check for proper lengths */ ($localLength > 0 && $localLength < 65) && ($domainLength > 3 && $domainLength < 256) && (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')));
}
if (isset($_POST['email'])) {
// E-Mail To:
$email_to = "
[email protected]";
$email_subject = "Site Form Feedback";
function died($error)
{
// your error code can go here
echo "There were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error . "<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if (!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) {
died('There appears to be a problem with the form you submitted.');
}
$error_message = "";
if (!isValidEmail($_POST['email'])) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[a-z.'-]+$/i";
if (!preg_match($string_exp, $_POST['first_name'])) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if (!preg_match($string_exp, $_POST['last_name'])) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if (strlen($_POST['comments']) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if (strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string)
{
$bad = array(
"content-type",
"bcc:",
"to:",
"cc:",
"href"
);
return str_replace($bad, "", $string);
}
$email_message .= "First Name: " . clean_string($_POST['first_name']) . "\n";
$email_message .= "Last Name: " . clean_string($_POST['last_name']) . "\n";
$email_message .= "Email: " . clean_string($_POST['email']) . "\n";
$email_message .= "Telephone: " . clean_string($_POST['telephone']) . "\n";
$email_message .= "Comments: " . clean_string($_POST['comments']) . "\n";
// create email headers
$headers = 'From:
[email protected]' . "\r\n";
'Reply-To: ' . $_POST['email'] . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting me. I will be in touch with you very soon.
<?php
}
?>
I receive the success message "Thank you for contacting me, etc." upon clicking the submit button. The mail does not arrive in the inbox. It is not in the spam folder or in a queue.
I talked to my server and they see no reason that mail is not arriving, barring some coding issue.
Mail arrives in the inbox when sending directly from another email account; it only fails when being sent through the contact form.
I would so appreciate any help; you just have no idea how much.