I recently built a contact form for a client and am putting the data into a table and then sending the data to 3-5 recepients using the mail function.
the data is being put into a table no problem whatsoever. but with the mail() function i am getting crazy, mixed results.
ex: I get the mail right away at all 3 of my mail accounts (on diff hosts). my client is not getting them at all, and a test subject, received an email at today at 2:20 a.m. that was sent on Friday afternoon!
i don’t know what to make of this?
are there any know issues with this function?, or any alternatives to using it.
the client is on a commercial shared hosting provider. i’ll include the code just in case it’s on my end.
[code=php]<?php
if (isset($_POST[‘submit’])) {
echo “<p>submitted</p>”;
$name = $_POST[‘name’];
$email = $_POST[’email’];
$subject = $_POST[‘subject’];
$message = $_POST[‘message’];
$date = date(“m/d/y”);
$mail_to_r1 = ‘[email protected]’;
$mail_to_r2 = ‘[email protected]’;
$mail_to_r3 = ‘[email protected]’;
$esubject = ‘New Mail from Contact Form’;
$emessage = ‘From: ‘ . $name . “n”;
$emessage .= ‘Email: ‘ . $email . “n”;
$emessage .= ‘Subject: ‘ . $subject . “n”;
$emessage .= “Message:n” . $message . “nn”;
// $name = $_POST[‘name’];
if ($name != “” && $name != “Name:”) {
$name = filter_var($_POST[‘name’], FILTER_SANITIZE_STRING);
if ($name == “”) {
$errors .= ‘Please enter a valid name.<br/><br/>’;
echo $errors;
}
} else {
$errors .= ‘Please enter your name.<br/>’;
echo $errors;
}
if ($email != “” && $email != ‘Email:’) {
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors .= “$email is <strong>NOT</strong> a valid email address.<br/><br/>”;
}
} else {
$errors .= ‘Please enter your email address.<br/>’;
}
if ($subject != “” && $subject != ‘Subject:’) {
$subject = filter_var($subject, FILTER_SANITIZE_STRING);
if ($subject == “”) {
$errors .= ‘Please enter a Subject.<br/>’;
}
} else {
$errors .= ‘Please enter a Subject.<br/>’;
}
if ($message != “” && $message != ‘Message:’) {
$message = filter_var($message, FILTER_SANITIZE_STRING);
if ($message == “”) {
$errors .= ‘Please enter a Message.<br/>’;
}
} else {
$errors .= ‘Please enter a Message.<br/>’;
}
//echo “This is the $name”;
$connection = mysql_connect(“localhost”, “root”, “password”);
if(!$connection) {
die(“Database connection failed: ” . mysql_error());
} //else {echo “<p>connection successful</p>”;}
//2. Select a database to use
$db_select = mysql_select_db(“database”, $connection);
if(!$db_select) {
die(“Database selection failed: ” . mysql_error());
} //else {echo “<p>connection successful</p>”;}
$query = “INSERT INTO contact_form (name, email, subject, message, date) VALUES (‘$name’, ‘$email’, ‘$subject’, ‘$message’, ‘$date’)”;
if(!$errors) {
mail($mail_to_r1, $esubject, $emessage);
mail($mail_to_r2, $esubject, $emessage);
mail($mail_to_r3, $esubject, $emessage);
header(“Location: http://www.whatever.com/sent”);
} else {
//echo “<p>There were errors</p>”;
//echo $errors;
header(“Location: http://www.whatever.domain.com/email-error.php”);
}
} // END IF SUBMIT
?>