PDA

View Full Version : Form not sending one field of information



michellemax
19 Nov 2010, 01:19 PM
I have a "contact us" form with the basic contact info.
Name, address, email, fax number etc are included in the email that gets sent.
The phone number field does not come through in the email...I haven't done many of these and I can't figure out why the phone number field is not being included in the email. Any suggestions would be greatly appreciated. :)

Thank you


Here is the form code:
<!-- form -->
<form method="post" name="" id="contactForm" action="process.php" accept-charset="utf-8">
<table id="contactForm">
<tr>
<td>First name<br />
<input type="text" name="fname" id="fname" value="" maxlength="100" /></td>
<td>Last name<br />
<input type="text" name="lname" id="lname" value="" maxlength="100" /></td>
</tr>
<tr>
<td colspan="2">Address<br />
<input type="text" name="address" id="address" value="" maxlength="100" /></td>
</tr>
<tr>
<td>City<br />
<input type="text" name="city" id="city" value="" maxlength="100" /></td>
<td>State/Postal Code<br />
<input type="text" name="state" id="state" value="" maxlength="100" /><input type="text" name="zip" id="zip" value="" maxlength="100" /></td>
</tr>
<tr>
<td colspan="2">Email<br />
<input type="text" name="email" id="email" value="" maxlength="100" /></td>
</tr>
<tr>
<td>Phone<br />
<input type="text" name="phone" id="phone" value="" maxlength="100" /></td>
<td>Fax<br />
<input type="text" name="fax" id="fax" value="" maxlength="100" /></td>
</tr>
<tr>
<td>How did you hear about Sunco?<br />
<input type="text" name="howHear" id="howHear" value="" maxlength="100" />
</td>
<td>Are you a:<br />
<input type="checkbox" name="customerType" value="Consumer" />&nbsp;Consumer
<input type="checkbox" name="customerType" value="Dealer" />&nbsp;Dealer</td>
</tr>
<tr>
<td colspan="2">Questions/Comments<br /><textarea name="comments" id="comments"></textarea><input type="image" id="submit" src="../images/submit.png" value="Submit" />
</td>
</tr>
</table>
</form>

And the corresponding php code:

<?php
if(empty($_POST['fname'])) {
$fname = '';
}
else {
$fname = $_POST['fname'];
}
if(empty($_POST['lname'])) {
$lname = '';
}
else {
$lname = $_POST['lname'];
}
if(empty($_POST['address'])) {
$address = '';
}
else {
$address = $_POST['address'];
}
if(empty($_POST['city'])) {
$city = '';
}
else {
$city = $_POST['city'];
}
if(empty($_POST['state'])) {
$state = '';
}
else {
$state = $_POST['state'];
}
if(empty($_POST['zip'])) {
$zip = '';
}
else {
$zip = $_POST['zip'];
}
if(empty($_POST['email'])) {
$email = '';
}
else {
$email = $_POST['email'];
}
if(empty($_POST['phone'])) {
$phone = '';
}
else {
$phone = $_POST['phone'];
}
if(empty($_POST['fax'])) {
$fax = '';
}
else {
$fax = $_POST['fax'];
}
if(empty($_POST['howHear'])) {
$howHear = '';
}
else {
$howHear = $_POST['howHear'];
}
if(empty($_POST['customerType'])) {
$customerType = '';
}
else {
$customerType = $_POST['customerType'];
}
if(empty($_POST['comments'])) {
$comments = '';
}
else {
$comments = $_POST['comments'];
}

$today = date("m-d-Y H:i a");

$msg = "Website Contact Form Submission\n";
$msg .= "Date Posted: $today\n\n";

$msg .= "Name: $fname $lname\n";
$msg .= "$address\n";
$msg .= "$city, $state $zip\n\n";
$msg .= "Tel. $tel\n";
$msg .= "Fax. $fax\n";
$msg .= "Email. $email\n\n";

$msg .= "How did you hear about us?: $howHear\n\n";

$msg .= "Customer Type: $customerType\n\n";

$msg .= "Comments: $comments";


$to = 'xxx@xxxx.com';
$from = 'request@xxx.com';
$subject = 'Contact Form Submission';
$body = $msg;

// prevent mailform hijacking
function safermail($to,$subject,$body,$from) {
$bad = array("\n","\r","\t","\0",",","%0A","%0D","%08","%09");
$good = "?";
$to = str_replace($bad,$good,$to);
$subject= str_replace($bad,$good,$subject);
$from = str_replace($bad,$good,$from);
$addlhdr = "From: $from\nReply-To: $from\n";
return mail ($to,$subject,$body,$addlhdr);
}
safermail($to,$subject,$body,$from);

header("Location: thank-you.html");
exit;