Thanks for viewing.
I'm new to php and have a piece of code that I modified to try to use for a simple "email submission". I need help figuring out a problem with the code.
Everything works fine except it returns back a "undefined" string after the email is submitted. I get the email and the "email error checker" works but it does not return back the "Thank you".
any help would be great.
<?php
function emailOK($str) {
if(empty($str)) return false;
if(!ereg("@",$str)) return false;
if(!ereg("\.",$str)) return false;
list($user, $host) = explode("@", $str);
if((empty($user)) || (empty($host))) return false;
$badChars = "[ ]+| |\+|=|[|]|{|}|`|\(|\)|,|;|:|!|<|>|%|\*|/|'|\"|~|\?|#|\\$|\\&|\\^|www[.]";
return !eregi($badChars, $str);
}
function readTextFile($file){
if(!($fp=@fopen($file,"r"))) return false;
$fileContent="";
while (!feof($fp)) {
$fileContent.= fgets($fp, 1024);
}
if(!fclose($fp)) return false;
return($fileContent);
}
function sendMsg($to, $toEmail, $sub, $msg, $from, $fromEmail) {
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n"; //The mailer name
$headers .= "From: ".$from."<".$fromEmail.">\r\n";
$headers .= "Reply-to: ".$from."<".$fromEmail.">\r\n";
$recipient = empty($to) ? $toEmail : $to."<".$toEmail.">";
return mail($recipient, $sub, $msg, $headers);
}
function cleanUpData($data){
$data=trim($data);
if(get_magic_quotes_gpc()){
$data=stripslashes($data);
}
return($data);
}
function flashEmail($postVars){
$name = "EXAMPLE.COM";
$email = cleanUpData(urldecode($postVars["email"]));
$message = "NEWSLETTER SUBSCRIPTION";
/*ERROR CHECKING*/
if (empty($email)) {
$status = "Email is empty!\nTry again";
die("status=".urlencode($status)."&sent=0&");
}
if (!emailOK($email)) {
$status = "Email is invalid!\nPlease try again.";
die("status=".urlencode($status)."&sent=0&");
}
/*###########################*/
//Everything looks good.. we are still alive!
$subject = "We have a new example.com subscriber";
$ourName = "www.example.com";
$ourEmail = "xxxx@example.com";
$ourVersion = readTextFile("sub_websiteMail.txt");
$ourVersion = ereg_replace("\{greetings\}", "Wake up!", $ourVersion);
$ourVersion = ereg_replace("\{date\}", date("m/d/Y"), $ourVersion);
$ourVersion = ereg_replace("\{email\}", $email, $ourVersion);
$tTasks = 1;
$tDone = 0;
if (sendMsg($ourName, $ourEmail, $subject, $ourVersion, empty($name) ? $email : $name, $email)) $tDone++;
if ($tDone = $tTasks)
{
$status = "Thank you!";
print "status=".urlencode($status)."&sent=1&";
return true;
} else {
$status = "Could not send message because of an internal server error\nPlease try again";
die("status=".urlencode($status)."&sent=0&");
}
}
flashEmail($HTTP_POST_VARS);
?>