PDA

View Full Version : Email with validation


johnnybananas
12-17-2005, 12:10 AM
I am trying to get the following email script to work but keep getting the following message...

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/public_html/water_folder/subscribe.php on line 12


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Email Sign-up</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body><?php
$referer = "somedomain.com";

if (getenv("REQUEST_METHOD") == "GET"){
echo "You may only use this script using the ""POST"" method";
exit;
}
if (!(preg_match("/$referer/i", "$HTTP_REFERER"))){
echo "You are accessing this script from an unauthorized domain.";
exit;
}
else {
$checkpoint = ereg("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,3}$",$email);
if($checkpoint==0) {
// if no valid email address entered, display no email message
echo "You <b>must</b> specify a valid email address. <a href=javascript:history.back(-1)>Return to the form</a>.";
}
else {
mail("someemail@yahoo.com", "Guest", $message, "From: $email");
echo "Congratulations. Your Email was sent successfully."; // if all went well, thank user
}
}
?>
<form action="" method="post">

Your email: <input name="email" type="text" size="20" maxlength="200" value="enter your email address">

<input type="submit" name="submit" value="Sign up">

</form>
</body>
</html>


Any suggestions please?

Element
12-17-2005, 12:26 AM
I am trying to get the following email script to work but keep getting the following message...

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/public_html/water_folder/subscribe.php on line 12


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Email Sign-up</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body><?php
$referer = "somedomain.com";

if (getenv("REQUEST_METHOD") == "GET"){
echo "You may only use this script using the ""POST"" method";
exit;
}
if (!(preg_match("/$referer/i", "$HTTP_REFERER"))){
echo "You are accessing this script from an unauthorized domain.";
exit;
}
else {
$checkpoint = ereg("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,3}$",$email);
if($checkpoint==0) {
// if no valid email address entered, display no email message
echo "You <b>must</b> specify a valid email address. <a href=javascript:history.back(-1)>Return to the form</a>.";
}
else {
mail("someemail@yahoo.com", "Guest", $message, "From: $email");
echo "Congratulations. Your Email was sent successfully."; // if all went well, thank user
}
}
?>
<form action="" method="post">

Your email: <input name="email" type="text" size="20" maxlength="200" value="enter your email address">

<input type="submit" name="submit" value="Sign up">

</form>
</body>
</html>


Any suggestions please?

echo "You may only use this script using the \"POST\" method";

johnnybananas
12-17-2005, 12:41 AM
Thank you element. That helped somewhat. I know get the following message...

You may only use this script using the "POST" method

Element
12-17-2005, 01:29 AM
Thank you element. That helped somewhat. I know get the following message...

You may only use this script using the "POST" method

My bad, I should have caught that.


if (!(empty($_GET))) { //
die("You may only use this script using the \"POST\" method");
}


Changed a bit, this way it will still die even if $_POST is set and $_GET is set.

missing-score
12-17-2005, 04:15 AM
The code directly above wont work, as $_GET will by default be an empty array, and also, theres no saying what get and post variables will be set...

Element
12-17-2005, 04:54 AM
The code directly above wont work, as $_GET will by default be an empty array, and also, theres no saying what get and post variables will be set...

Eh it works for me, though !(empty($_GET) will check if the array isn't empty.

Also, why bother posting if you have nothing to add besides a negetive? If it doesn't work he would obviously post back, or you could post the alternative code that does work. Simply saying something won't work that way doesn't help.

missing-score
12-17-2005, 04:57 AM
But the $_GET and $_POST variables will, by default, be empty arrays... they are both set, and as such the script will never die. I dont know about earlier PHP versions, I'm only basing this on what I'm using.

Are you sure you arent thinking of empty()?

Element
12-17-2005, 05:09 AM
But the $_GET and $_POST variables will, by default, be empty arrays... they are both set, and as such the script will never die. I dont know about earlier PHP versions, I'm only basing this on what I'm using.

Are you sure you arent thinking of empty()?

Didn't see your post, yeah thats what I just edited it to. :thumbsup: