Oh.... hmm...
Use this:
'cause you'll need to NOT add to the list if it's invalid. right.
PHP Code:
<?php
if ($email = stripslashes($_POST['email'])) {
$filename = "emails.phplist";
$at = strpos($email, "@");
$dot = strpos($email, ".", $at+2);
$atnum = substr_count($email, "@");
if ($at == false or $dot == false or $dot == strlen($email) or $atnum > 1)
{ $bad email = "The email address you entered is not valid. Please go back and try again.<br>"; }
else {
$filecontents = @file_get_contents($filename);
if ($_POST['choice'] == "join") {
if (strpos($filecontents, $email) != "") break;
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.";
}
elseif ($_POST['choice'] == "leave") {
$edited = str_replace($email,"",$filecontents);
$file = @fopen($filename, "w+");
@fwrite($file, $edited);
@fclose($file);
$message = "Your email was removed from the mailing list.";
}
mail("tom@curiousclothing.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.", "From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/".phpversion());
}
}
?>
Bookmarks