samedi 28 mars 2015

Contact form handler suddenly doesn’t send emails to Gmail

I did a “raw” PHP contact form sender a year ago, tested many times, it worked. It should just send an email to a Gmail account with the submitted email address or contact form parameters included in email body.


Now on redesign I got back to the contact form, tested it randomly and it doesn’t send anything at all. No error messages, the submitted form never arrives in the main Gmail inbox, unlike it used to.



<?php
$errors = '';
$myemail = 'x@gmail.com';
$noreply = 'x@y.com';

if (empty($_POST['email']))
{
$errors .= "\n Error: Please provide an e-mail address where we can send the newsletter and special deals";
}

$email_address = $_POST['email'];

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}

if (empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $email_address";
$email_body = "You have received a newsletter signup. ".
"Email: $email_address";

$headers = "From: $noreply\n";
$headers .= "Reply-To: $email_address";

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: newsletter_submit.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ift.tt/kTyqzh">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>


It did happen with another similar form on this website, I wonder if something’s wrong with the code (althought it worked once) or Gmail changed something. I tried whitelisting the form sender email, but nothing changed.


Aucun commentaire:

Enregistrer un commentaire