I have a script that takes a name, email, and zip and sends an email to the subscription program.
Two things are wrong here: error checking doesn't work and when ever I run the script as is, I get nothing back (appears to be a fatal error)
There were some problems with the mail server last week, but that shouldn't cause a fatal, especially not once the problem is fixed, although I haven't touched this for a month and it was working then.
My guess is that it is the code, and probably one of those stupid little mistakes that cause you great and immeasurable pain (:D).
Code: Select all
<?php
ini_set('display_errors','1');
$store=isset($_GET['store'])?$_GET['store']:"";
if(empty($store)){$store='store1';}
$recipient="$store@website.com";
$output="<html><head><title>Thank You!</title></head><body>";
$full_store=($store=='store1')?"Store 1":"Store 2";
$email=parseEmailAddr($_POST['email']);
$name ="";//$_POST['personname']; - this is how I know error checking doesn't work
$zip =$_POST['zip'];
$error=false;
if (empty($email)) {
$output.="<strong>Please fill out your correct email address</strong><br>";
$error=true;
}
if (empty($name)) {
$output.="<strong>Please fill out your name</strong><br>";
$error=true;
}
if (empty($zip)) {
$output.="<strong>Please fill out your zip code</strong><br>";
$error=true;
}
if ($error) {
$output.="<a href='javascript:history.go(-1)'>Go Back</a><br>";
} elseif (!$error) {
$msg=<<<ENDMSG
---------------------------------
$full_store email addition:
---------------------------------
Email Address: $email
Zip: $zip
Individual's Name:$name
ENDMSG; //'
if (mail($recipient,"website.com",$msg,"From:$email ($name)")) {
$output.="<div align='center'>Great, we'll add you to our mailing list!</div>";
} else {
$output.="<strong>There has been a problem with the email subscription. Please check back and suscribe once the issue has been resolved.</strong>";
}
}
$output.="</body></html>";
echo $output;
function parseEmailAddr($emailAddr){
if (!preg_match("/^(.+)@([^();:,<>]+.[a-zA-Z]{2,4})/",$emailAddr)) {
return "";
}
return $emailAddr;
}
?>