Help on PHP Email form
Posted: Thu Apr 23, 2009 10:11 pm
I am new to PHP and I seriously need help with this. I created a form.php and formprocessor.php..but when I ran it ..give me parse errors...I checked my spelling..everything..but couldn't figure out...any help will be appreciated
form.php
phpprocessor.php
form.php
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Untitled document</title>
</head>
<body>
<form name="contactform" method="post" action="desktops_processor.php">
<table width="450">
<tbody>
<tr>
<td valign="top"><label for="first_name">First Name <span style="color: #ff0000;">*</span></label></td>
<td valign="top"><input name="first_name" maxlength="50" size="30" type="text" /></td>
</tr>
<tr>
<td valign="top"><label for="last_name">Last Name <span style="color: #ff0000;">*</span></label></td>
<td valign="top"><input name="last_name" maxlength="50" size="30" type="text" /></td>
</tr>
<td valign="top"><label for="address">Address<span style="color: #ff0000;">*</span></label></td>
<td valign="top"><input name="address" maxlength="50" size="40" type="text" /></td>
</tr>
<td valign="top"><label for="city">City<span style="color: #ff0000;">*</span></label></td>
<td valign="top"><input name="city" maxlength="50" size="40" type="text" /></td>
</tr>
<td valign="top"><label for="state">State</span></label></td>
<td valign="top"><select name="state">
<option>UT</option>
</select>
</td>
</tr>
<td valign="top"><label for="zipcode">Zip Code:</span></label></td>
<td valign="top"><input name="zipcode" maxlength="5" size="5" type="text" /></td>
</tr>
<td valign="top"><label for="telephone">Phone <span style="color: #ff0000;">*</span></label></td>
<td valign="top"><input name="telephone" maxlength="10" size="10" type="text" /><lable>(XXX.XXX.XXXX)</lable></td>
</tr>
<tr>
<td valign="top"><label for="comments">Comments <span style="color: #ff0000;">*</span></label></td>
<td valign="top"><textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea></td>
</tr>
<tr>
<tr>
<td colspan="2" style="text-align:center"><input value="Submit" type="submit" />
<input value="Clear" type="reset" /></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
phpprocessor.php
Code: Select all
<?php
if(isset($_POST['email'])) {
$email_to = "email@email.com";
$email_subject = "Title";
function died($error) {
// your error code can go here
//echo "There is error with your input!";
echo "Please fix the following errors:<br /><br />";
echo $error."<br /><br />";
//echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['address']) ||
!isset($_POST['city']) ||
!isset($_POST['state']) ||
!isset($_POST['zipcode']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form your submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$address = $_POST['address']; //required
$city = $_POST['city']; //required
$state = $_POST['state']; //not required
$zipcode = $_POST['zipcode']; //required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$first_name)) {
$error_message .= 'First Name.<br />';
}
if(!eregi($string_exp,$last_name)) {
$error_message .= 'Last Name<br />';
}
$string_exp = "^[1-9][0-9]*\s+([a-zA-Z]+|[a-zA-Z]+\s+[a-zA-Z]+|[a-zA Z]+\s+[a-zA-Z]+\s+[a-zA-Z]+|[a-zA-Z]+\s+[1-9][0-9]*\s+[a-zA-Z]+|[a-zA-Z]+\.\s+[1-9][0-9]*\s+[a-zA-Z]+\.)$";
if(!eregi($string_exp,$address)) {
$error_message .= 'Address<br />';
}
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$city)) {
$error_message .= 'City.<br />';
$string_exp = "^[A-Z]{2,2}";
if(!eregi($string_exp,$state)) {
$error_message .= 'State.<br />';
$string_exp = "^\d{5}$";
if(!eregi($string_exp,$zipcode)) {
$error_message .= 'ZipCode.<br />';
$string_exp = "^[0-9 .-]+$";
if(!eregi($string_exp,$telephone)) {
$error_message .= 'Phone Number<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'Comments<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Adress: ".clean_string($address)."\n";
$email_message .= "City: ".clean_string($city)."\n";
$email_message .= "State: ".clean_string($state)."\n";
$email_message .= "ZipCode: ".clean_string($zipcode)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
@mail($email_to, $email_subject, $email_message);
?>
Thank you!
<?
}
?>