Form Mailer Problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
david101
Forum Newbie
Posts: 1
Joined: Mon Mar 21, 2011 12:44 am

Form Mailer Problems

Post by david101 »

I'd truly appreciate any help you can give me with the following PHP form mailer. I get the following error: Parse error: syntax error, unexpected T_ELSE in testcontact.php on line 31
Any ideas on how to fix the error?

Also, I need to sanitize the data, but I don't understand how to. Everything I've googled doesn't seem to work.

Code: Select all

<?php

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$mailinglist = $_POST['mailinglist'];
$companyname = $_POST['companyname'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$countrycode = $_POST['countrycode'];
$areacode = $_POST['areacode'];
$citycode = $_POST['citycode'];
$number = $_POST['number'];
$fcountrycode = $_POST['fcountrycode'];
$fareacode = $_POST['fareacode'];
$fcitycode = $_POST['fcitycode'];
$fnumber = $_POST['fnumber'];
$industry = $_POST['industry'];
$product = $_POST['product'];
$productnumber = $_POST['productnumber'];
$comments = $_POST['comments'];

if ($mailinglist != yes)
 $mailinglist = no;
 

$mail_to = 'example@isp.com';  
$subject = 'Webform Data';  
$body = "First Name: $firstname \n Last Name: $lastname: \n Email: $email \n Mailing List: $mailinglist \n Company Name: $companyname \n Address: $address \n City: $city \n Zip: $zip \n Phone: $countrycode $areacode $citycode $number \n Fax: $fcountrycode $fareacode $fcitycode $fnumber \n Industry: $industry \n Product: $product \n Number of Packaged Products: $productnumber \n Comments/Questions: $commments ";

if (isset($_POST['Submit'])) {  
 	mail($to, $subject, $body);
	echo "You will be contacted shortly."; 
	}; 
?>

<!DOCTYPE html PUBLIC "/W3C/DTD XHTML 1.0 Transitional/EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="main.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact Us</title>
</head>
<form action="testcontact.php" method="post">* represents required field<br />
*First Name:<input name="firstname" type="text" maxlength="50" value="<?php echo $_POST['firstname']; ?>" /><br /> 
*Last Name:<input name="lastname" type="text" maxlength="50" value="<?php echo $_POST['lastname']; ?>" /><br /> 
*E-mail:<input name="email" type="text" maxlength="50" value="<?php echo $_POST['email']; ?>" /><br /> 
Join Mailing List(check if yes):<input name="mailinglist" type="checkbox" value="<?php echo $_POST['mailinglist']; ?>"/><br />
Company Name:<input name="companyname" type="text" maxlength="100" value="<?php echo $_POST['companyname']; ?>" /><br /> 
Address:<input name="address" type="text" maxlength="100" value="<?php echo $_POST['address']; ?>" /><br /> 
City:<input name="city" type="text" maxlength="100" value="<?php echo $_POST['city']; ?>" /><br /> 
Zip<input name="zip" type="text" maxlength="10" value="<?php echo $_POST['zip']; ?>" /><br /> 
Phone Number:<input name="countrycode" type="text" size="3" maxlength="3" value="<?php echo $_POST['countrycode']; ?>" />-<input name="areacode" type="text" size="3" maxlength="3" value="<?php echo $_POST['areacode']; ?>" />-<input name="citycode" type="text" size="3" maxlength="3" value="<?php echo $_POST['citycode']; ?>" />-<input name="number" type="text" size="4" maxlength="4" value="<?php echo $_POST['number']; ?>" /><br />
Fax:<input name="fcountrycode" type="text" size="3" maxlength="3" value="<?php echo $_POST['fcountrycode']; ?>" />-<input name="fareacode" type="text" size="3" maxlength="3" value="<?php echo $_POST['fareacode']; ?>" />-<input name="fcitycode" type="text" size="3" maxlength="3" value="<?php echo $_POST['fcitycode']; ?>" />-<input name="fnumber" type="text" size="4" maxlength="4" value="<?php echo $_POST['fnumber']; ?>" /><br /> 
Industry:<input name="industry" type="text" maxlength="50" value="<?php echo $_POST['industry']; ?>" /><br />
Product Packaged:<input name="product" type="text" maxlength="100" value="<?php echo $_POST['product']; ?>" /><br />
Number of Packaged Products:<input name="productnumber" type="text" maxlength="100" value="productnumber" /><br />
Comments/Questions:<br /><textarea name="comments" rows="5" cols="50" maxlength="10000"><?php echo $_POST['comments']; ?></textarea><br /> 
<input type="submit" value="submit" /> 
</form> 
</body>
</html>

Thanks!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Form Mailer Problems

Post by social_experiment »

Code: Select all

if ($mailinglist != yes)
 $mailinglist = no; 
 // try this
 if ($mailinglist != 'yes') {
   $mailinglist = 'no';
 }
To equate (or test) the value of a string, you have to wrap the string to check for (in your example 'yes') in quotation marks. YES / NO is not the same as TRUE / FALSE in php.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply