Forum Moderators: coopster

Message Too Old, No Replies

I got email from my webform but no data in the email

webform

         

gaminuniverse

9:06 pm on Jul 20, 2010 (gmt 0)

10+ Year Member



I created a webform and PHP file. They are work. I mean when I submit the form which will be sent to my email, but there is no data included in the email.

I tried to find errors in the code but really found nothing. Could you please help me....


My webform code (Html)


<form id="form1" name="form1" method="post" action="contactformprocess.php">
<table width="648" border="0" cellspacing="2">
<tr>
<td width="227"><label for="salutation">Salutation</label></td>
<td width="405"> <input name="salutation" type="text" id="salutation" size="55" maxlength="5" /></td>
</tr>
<tr>
<td><label for="name">First Name</label></td>
<td><input name="name" type="text" id="name" onblur="MM_validateForm('name','','R');return document.MM_returnValue" size="55" maxlength="34" /></td>
</tr>
<tr>
<td><label for="lastname">Last Name*</label></td>
<td width="405" height="20"><input name="lastname" type="text" id="lastname" onblur="MM_validateForm('lastname','','R');return document.MM_returnValue" size="55" maxlength="20" /></td>
</tr>
<tr>
<td><label for="dateofbirth">Date of Birth (mm/dd/yyyy)*</label></td>
<td><input name="dateofbirth" type="text" id="dateofbirth" onblur="MM_validateForm('dateofbirth','','R');return document.MM_returnValue" size="55" maxlength="10" /></td>
</tr>
<tr>
<td><label for="email">Email Address*</label></td>
<td><input name="email" type="text" id="email" onblur="MM_validateForm('email','','RisEmail');return document.MM_returnValue" size="55" maxlength="30" /></td>
</tr>
<tr>
<td><label for="address">Address*</label></td>
<td><input name="address" type="text" id="address" onblur="MM_validateForm('address','','R');return document.MM_returnValue" size="55" maxlength="40" /></td>
</tr>
<tr>
<td><label for="city">City*</label></td>
<td><input name="city" type="text" id="city" onblur="MM_validateForm('city','','R');return document.MM_returnValue" size="55" maxlength="30" /></td>
</tr>
<tr>
<td><label for="state">State*</label></td>
<td><input name="state" type="text" id="state" onblur="MM_validateForm('state','','R');return document.MM_returnValue" size="55" maxlength="20" /></td>
</tr>
<tr>
<td><label for="zip">Zip*</label></td>
<td><input name="zip" type="text" id="zip" onblur="MM_validateForm('zip','','RisNum');return document.MM_returnValue" size="55" maxlength="15" /></td>
</tr>
<tr>
<td><label for="insurance">Insurance*</label></td>
<td><input name="insurance" type="text" id="insurance" onblur="MM_validateForm('insurance','','R');return document.MM_returnValue" size="55" maxlength="35" /></td>
</tr>
<tr>
<td><label for="phone">Primary Phone*</label></td>
<td><input name="phone" type="text" id="phone" size="55" maxlength="12" /></td>
</tr>
<tr>
<td><label for="cellphone">Cell Phone</label></td>
<td><input name="cellphone" type="text" id="cellphone" size="55" maxlength="12" /></td>
</tr>
<tr>
<td><label for="employer">Employer Name</label></td>
<td><input name="employer" type="text" id="employer" size="55" maxlength="30" /></td>
</tr>
<tr>
<td><label for="employeraddress">Employer Phone</label></td>
<td><input name="employeraddress" type="text" id="employeraddress" size="55" maxlength="15" /></td>
</tr>
<tr>
<td><label for="employeraddress">Employer Address</label></td>
<td><input name="employeraddress2" type="text" id="employeraddress2" size="55" maxlength="50" /></td>
</tr>
<tr>
<td><label for="hearaboutus">Hear about us*</label></td>
<td><input name="hearaboutus" type="text" id="hearaboutus" onblur="MM_validateForm('hearaboutus','','R');return document.MM_returnValue" size="55" maxlength="75" /></td>
</tr>
<tr>
<td><label for="comments">Comments</label></td>
<td><textarea name="comments" cols="43" rows="5" id="comments"></textarea></td>
</tr>
<tr>
<td>Subscribe for FREE newsletter!</td>
<td><input name="newsletter" type="checkbox" id="newsletter" value="Subscribe to our FREE online Newsletter" checked="checked" /></td>
</tr>
<tr>
<td height="93"><label for="reset"></label>
<input type="reset" name="reset" id="reset" value="Reset Form" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit the Form" /></td>
</tr>
</table>
</form>

My PHP code


<?php

/* Subject and Email Variables */

$emailSubject = 'Crazy PHP Scripting!';
$webMaster = 'contactdocs@inovadocs.com';

/* Gathering Data Variables */

$salutationField = $_POST['salutation'];
$nameField = $_POST['name'];
$lastnameField = $_POST['lastname'];
$dateofbirthField = $_POST['dateofbirth'];
$emailField = $_POST['email'];
$addressField = $_POST['address'];
$cityField = $_POST['city'];
$stateField = $_POST['state'];
$zipField = $_POST['zip'];
$insuranceField = $_POST['insurance'];
$phoneField = $_POST['phone'];
$cellphoneField = $_POST['cellphone'];
$employerField = $_POST['employer'];
$employeraddressField = $_POST['employeraddress'];
$employeraddress2Field = $_POST['employeraddress2'];
$hearaboutusField = $_POST['hearaboutus'];
$commentsField = $_POST['comments'];
$newsletterField = $_POST['newsletter'];

$body = <<<EOD
<br><hr><br>
Salutation: $salutation <br>
First Name: $name <br>
Last Name: $lastname <br>
Date of Birth: $dateofbirth <br>
Email: $email <br>
Address: $address <br>
City: $city <br>
State: $state <br>
Zip: $zip <br>
Insurance: $insurance <br>
Primary Phone: $phone <br>
Cell Phone: $cellphone <br>
Employer: $employer <br>
Employer Phone: $employeraddress <br>
Employer Address: $employeraddress2 <br>
Hear About Us: $hearaboutus <br>
Comments: $comments <br>
Newsletter: $newsletter <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/* Results rendered as HTML */
$theResults = <<<EOD
<html>
<head>
<title>JakesWorks - travel made easy-Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
-->
</style>
</head>

<div>
<div align="left">Thank you for your register</div>
</div>
</body>
</html>
EOD;
echo "$theResults";


?>

Matthew1980

9:38 pm on Jul 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there gaminuniverse,

Welcome to the forum! :) [webmasterworld.com ]

Sounds obvious, but have you echoed the contents of $body and exited the script to see that var actually holds a value & holds the values as you would expect?

Try just debugging the constructed vars before it gets to the mail part, ie use the print_r($_POST) when the form is submitted to see if all of the filled in fields hold the data as it is submitted..

Because if you are submitting the form and there are no error checking in place you would get a submit go through & a success message displayed as there are no error handlers in place, so any values not set wouldn't matter and php would treat it as success. Hope that makes sense.

You may want to consider data sanitising too, you certainly don't want to get malicious code injections from an email, simple functions like strip_tags() will remove any html style tags from any data inputted.

Hope that helps a bit ;)

Cheers,
MRb

rocknbil

12:46 am on Jul 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First stop, the manual and note that mail() returns a boolean. So you do

if (mail([parameters]) {
// ok
}
else { die("Mail died."); }

or alternatively, you are storing it in $success so

if ($success) {
// the response you have there
}
else {
//output some error
}

Everything seems OK at first glance, see advice above.

gaminuniverse

4:45 am on Jul 23, 2010 (gmt 0)

10+ Year Member



Hello! Mr. MRb and Mr. Rocknbil

I tried changing things as your comments!
My page is work now!

Thank you sooooo much!