I’m trying to set up a newsletter sign-up form with only on text box ‘email’. If the box is not filled in you are sent to an error page. If it is filled in you are sent to a thank-you page.
Now I’ve got it working but have discovered a problem. Anyone can type in anything they want whether it’s an email address or not. I would like the form.php to recognize the “@” sign before sending, if it’s not there then the error page would appear. Any thoughts on what to change in the code below for this function to work? I haven’t been able to figure it out.
Thanks.
<?
//Declare the variables
$siteaddress ="http://www.default.com";
$sitename = "default design";
$adminaddress = "newsletter@default.com";
$subject = "SIGN UP";
//Gets date and time from server
$date = date("m/d/Y H:i:s");
// Gets the IP Address
if ($REMOTE_ADDR == "") $ip = "no ip";
else $ip = getHostByAddr($REMOTE_ADDR);
//Contents of form
//////////////////////////////////////////////////////////////////
$email = $_REQUEST['email'] ;
if (!isset($_REQUEST['email'])) {
header( "Location: http://www.default.com/thankyou.htm" );
}
elseif (empty($email)) {
header( "Location: http://www.default.com/error.htm" );
}
else {
header( "Location: http://www.default.com/thankyou.htm" );
/////////////////////////////////////////////////////////////////////
//mail() function sends the mail
mail ("$adminaddress","Info Request",
"A visitor at $sitename has left the following information
Email: $email
The visitor has subscribed to the NEWSLETTER.
------------------------------
Logged Info :
------------------------------
Using: $HTTP_USER_AGENT
Hostname: $ip
IP address: $REMOTE_ADDR
Date/Time: $date","FROM:$adminaddress" ) ;
//This sends a confirmation to your visitor
mail ("$email","Thank You for visiting $sitename",
"Hi $email,
Thank you for your interest in $sitename!
You have just subscribed to the default.com newsletter.
Thanks again!!
$sitename
CHANGING THE WORLD!
$siteaddress
$adminaddress", "FROM:$adminaddress") ;
}
//This line sends to thankyou page when finished
?>