Confirmation Email not showing up in GMail
I created an Email form that does two things: populates a mysql db and sends a confirmation email to the person who filled out the form. It works great except for one thing: the confirmation email is not showing up in gmail. When I send it to Outlook accounts or Hotmail and Yahoo, the confirmation arrives without a problem. I'm wondering why is it not working in gmail? Have any of you run into to this problem?
Here is the relevant code:
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if (function_exists('nukeMagicQuotes')) {
nukeMagicQuotes();
}
// process the email
if (array_key_exists('send', $_POST)) {
$to = $_REQUEST['email'];
$subject = 'Registration Form';
// expected fields
$expected = array('first_name', 'last_name', 'medtech_id', 'job_title', 'company', 'city', 'state', 'email', 'phone', 'contact_me');
// required fields
$required = array('first_name', 'last_name', 'job_title', 'company', 'city', 'state', 'email', 'phone');
// empty array for any missing fields
$missing = array();
// assume that there is nothing suspect
$suspect = false;
// create a pattern to locate suspect phrases
$pattern = '/Content-Type:|Bcc:|Cc:/i';
// function to check for suspect phrases
function isSuspect($val, $pattern, &$suspect) {
// if the variable is an array, loop through each element
// and pass it recursively back to the same function
if (is_array($val)) {
foreach ($val as $item) {
isSuspect($item, $pattern, $suspect);
}
}
else {
// if one of the suspect phrases is found, set Boolean to true
if (preg_match($pattern, $val)) {
$suspect = true;
}
}
}
// check the $_POST array and any sub-arrays for suspect content
isSuspect($_POST, $pattern, $suspect);
if ($suspect) {
$mailSent = false;
unset($missing);
}
else {
// process the $_POST variables
foreach ($_POST as $key => $value) {
// assign to temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
// if empty and required, add to $missing array
if (empty($temp) && in_array($key, $required)) {
array_push($missing, $key);
}
// otherwise, assign to a variable of the same name as $key
elseif (in_array($key, $expected)) {
${$key} = $temp;
}
}
}
// go ahead only if not suspect and all required fields OK
if (!$suspect && empty($missing)) {
// build the message
$message = 'Sample Message: Hello! You are registered!';
$message = wordwrap($message, 70);
$additionalHeaders = 'From: Registration Form on Web Site';
if (!empty($email)) {
$additionalHeaders .= "\r\nReply-To: $email";
}
$mailSent = mail($to, $subject, $message, $additionalHeaders);
if ($mailSent) {
}
}
}
