Jump to content

Can't figure out this error


Praetorian
 Share

Recommended Posts

I re-did my email code to condense it, and now I'm getting this error and I can't figure out why. "Parse error: syntax error, unexpected T_VARIABLE in /home/author/public_html/mail.php on line 13"Here's the script.

<?php$Name = $_REQUEST["Name"];$Email = $_REQUEST["Email"];$Message = $_REQUEST["Message"];$errors = Array();					if (($Name == "") or !eregi("[a-z]", $Name)	$errors[] = "<h3>Please enter a valid name.</h3>";if (($Email == "") or !eregi("^[a-z0-9]+([!#$%*/?|^{}`~&'+-=_][a-z0-9])*@[a-z0-9]+([!#$%*/?|^{}`~&'+-=_][a-z0-9])*.[a-z]{2,3}$", $Email))	$errors[] = "<h3>Please Enter a Valid Email Address.</h3>";if ($Message == "")	$errors[] = "<h3>Please enter a message.</h3>";						if (empty($errors) and isset($Email))   {	  mail( "*****",$Name,$Message,"From: $Email" );	  echo "<h1>Thank you for your message! One of the admins should be getting back to you via email within 24 hours.</h1>";	}   else   {	   foreach ($errors AS $e)		   echo $e;		   include 'mailform.txt';   }?>

Link to comment
Share on other sites

Well, I did some cleaning up, that is, I explicitly added "{" and "}" everywhere (indentation alone doesn't cut theese things for me), I saw a missing ")" somewhere (on line 7 I believe), replaced double quotes with single quotes wherever applicable, etc. and here it is:

<?php	$Name = $_REQUEST['Name'];	$Email = $_REQUEST['Email'];	$Message = $_REQUEST['Message'];	$errors = Array();		if ($Name == '' || !eregi('[a-z]', $Name)) {		$errors[] = '<h3>Please enter a valid name.</h3>';	}	if ($Email == '' || !eregi("^[a-z0-9]+([!#$%*/?|^{}`~&'+-=_][a-z0-9])*@[a-z0-9]+([!#$%*/?|^{}`~&'+-=_][a-z0-9])*.[a-z]{2,3}$", $Email)) {		$errors[] = '<h3>Please Enter a Valid Email Address.</h3>';	}	if ($Message == '') {		$errors[] = '<h3>Please enter a message.</h3>';	}	if (empty($errors) && isset($Email)) {		mail( "*****",$Name,$Message,"From: $Email" );		echo '<h1>Thank you for your message! One of the admins should be getting back to you via email within 24 hours.</h1>';	}else {		foreach ($errors AS $e) {			echo $e;			include 'mailform.txt';		}	}?>

See if that works. I can't exactly test it on my own.

Link to comment
Share on other sites

Hm. Must have been that missing ")". It works fine now. Though I had to remove all the {} you added. For some reason adding them to the foreach caused the included form to display once for each error, instead of displaying once with the errors all listed together.Thanks for the help.

Link to comment
Share on other sites

Hm. Must have been that missing ")". It works fine now. Though I had to remove all the {} you added. For some reason adding them to the foreach caused the included form to display once for each error, instead of displaying once with the errors all listed together.Thanks for the help.
If the form is in 'mailform.txt', then I suppose you can just move the include statement outside of the foreach and you're set:
else {		foreach ($errors AS $e) {			echo $e;		}		include 'mailform.txt';	}

But really, it's a good practice to explicitly have parenthesis everywhere. It increases readability, thus predictability and thus makes for easier debugging.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...