Page 1 of 1

Can't find the error, please help

Posted: Tue Jan 11, 2011 11:37 am
by danwguy
So I am writing a very simple code to validate a certain field on a form and send email if it's good or popup an alert if it's not but I keep getting... Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in send-mail.php on line 11 ... I have no freaking idea what that means, I have tried checking line 11 but as far as I can tell there is no problem with it. please help, Thank you.

Code: Select all

<?php
$cname = $_POST['companyName'];
$addy = $_POST['companyAddress'];
$cphone = $_POST['companyPhone'];
$name = $_POST['contactName'];
$phone = $_POST['contactPhone'];
$email = $_POST['contactEmail'];
$acct = $_POST['knocAccount'];
$to = 'myemailaddress';
$subject = 'New Account - ' . $name . 'From ' . $cname;
$message = "<html><head>	<title>New Account</title>	</head>	<body>	<p><b>Company Name:</b> "' . $cname . '"<br />	Company Address: "' . $addy . '"<br />	Company Phone: "' . $cphone . '"<br /><br />	<b>Contact Name:</b> "' . $name . '"<br />	Contact Phone: "' . $phone . '"<br />	Contact Email: "' . $email . '"<br />	Knox Account Number: "' . $acct '"<br />	</body>	</html>	";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	
if(!preg_match('/^[0-9]', $addy)) {
		echo "<script language='javascript'>alert('Please use a real address and try again')</script>";
		header("location: http://www.knoxservices.com/order/create-account.asp");
	}else{
		mail($to, $subject, $message, $headers);
		echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'><html><head><meta http-equiv='REFRESH' content='30;url=http://www.knoxservices.com/order/create-account.asp'><link href='../style.css' type='text/css' rel='stylesheet' /></head><body>";
		echo "<h2>Your information has been received!</h2><br /><p>Our account reps are reviewing your information now and will be contacting you soon with your new account information. Thanks for creating an account with us!<br />You will be redirected in 30 seconds</p></body></html>";
		}
?>

Re: Can't find the error, please help

Posted: Tue Jan 11, 2011 11:55 am
by s992
Try removing the single quotes from this section of code:

Code: Select all

Name:</b> "' . $cname . '"<br />  Company Address: "' . $addy . '"<br />  Company Phone: "' . $cphone . '"<br /><br />    <b>Contact Name:</b> "' . $name . '"<br />      Contact Phone: "' . $phone . '"<br />   Contact Email: "' . $email . '"<br />   Knox Account Number: "' . $acct '"<br />        </body> </html> ";
I don't see any reason why you would need to use single quotes here, it appears that the double quotes will work just fine, but doubling them up ('") is likely what's causing the error.

Re: Can't find the error, please help

Posted: Tue Jan 11, 2011 12:15 pm
by danwguy
Not sure if that fixed it or if I found it, probably both... but there was a part ...

Code: Select all

$message = "<html><head>	<title>New Account</title>	</head>	<body>	<p><b>Company Name:</b> " . $cname . "<br />	Company Address: " . $addy . "<br />	Company Phone: " . $cphone . "<br /><br />	<b>Contact Name:</b> " . $name . "<br />	Contact Phone: " . $phone . "<br />	Contact Email: " . $email . "<br />	Knox Account Number: " . $acct "<br />	</body>	</html>	";
I forgot to put a . after the . $acct " in there. I did what you suggested too and it all works great now. just a side note question sort of thingy, Will that preg_match work right? I want to be able to validate an address. Recently had a bot sending the form 50+ times a day and it doesn't use numbers so I figure if I validate that the first character in teh address field is a number it will stop the bot. does that sound right or am I not thinking correctly?
Thank you for the help.

Re: Can't find the error, please help

Posted: Tue Jan 11, 2011 12:24 pm
by s992
I'd recommend against validating the e-mail using a rule like that - it's perfectly possible that a real person might prefix their e-mail address with a number as well. There are a lot of solutions such as CAPTCHAs and other form protection methods that would be better suited to the task and wouldn't lock out a real person who is unfortunate enough to have an e-mail that starts with a number.

Re: Can't find the error, please help

Posted: Tue Jan 11, 2011 6:08 pm
by danwguy
I'm not validating email address with that code, I am validating their street address with that.