I have a form on our website that a user can fill out for custom product. I want the form data to be 1) stored into a mysql database AND after storing said data, 2) email the same data to our sales department.
1) The form data DOES get stored into mysql database (except for the first two fields, for some weird reason)
2) I added a "mail" section to the php file that stores the data into the database, but it is not working correctly. I have stripped the email portion down to sending just one of the fields in the "message" to make it easier for troubleshooting
I have included here, both the form section of the html file, and the formdata.php file that processes the data for your analysis. I am relatively new to php so there are going to be some issues with security, but I can work on those after I get the store & email process to work correctly. Please review my code and see if anyone can be of assistance. I looked through the forums and couldn't find another issue that was the same as mine. If I just overlooked, please tell me the thread post #. Thanks :)
THE FORM WHICH COLLECTS THE DATA
*******************************
<form method=POST action=formdata.php>
<table width="640" border=0 align="center">
<tr>
<td align=right><b>First Name</b></td>
<td><input type=text name=FName size=25></td>
<td><div align="right"><b>Telephone</b></div></td>
<td><input type=text name=Tel size=25></td>
</tr>
<tr>
<td align=right><b>Last Name</b></td>
<td><input type=text name=LName size=25></td>
<td><div align="right"><b>Fax</b></div></td>
<td><input type=text name=Fax size=25></td>
</tr>
<tr>
<td align=right><b>Title</b></td>
<td><input type=text name=Title size=25></td>
<td><div align="right"><b>Email</b></div></td>
<td><input type=text name=Email size=50></td>
</tr>
<tr>
<td align=right><b>Company</b></td>
<td><input type=text name=Comp size=25></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right><b>Address</b></td>
<td><input type=text name=Addr size=25></td>
<td><div align="right"><b>Estimated Annual Volume</b></div></td>
<td><input type=text name=EAV size=25></td>
</tr>
<tr>
<td align=right><b>City</b></td>
<td><input type=text name=City size=25></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right><b>State/Province</b></td>
<td><input type=text name=SProv size=25></td>
<td><div align="right"><b>Application</b></div></td>
<td><input type=text name=Appl size=25></td>
</tr>
<tr>
<td align=right><b>Country</b></td>
<td><input type=text name=Ctry size=25></td>
<td><div align="right"><b>Type of System</b></div></td>
<td><input type=text name=Syst size=25></td>
</tr>
<tr>
<td align=right><b>Zip/Postal Code</b></td>
<td><input type=text name=ZPC size=25></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right> </td>
<td><div align="right"><strong><font color="#FFFF00" face="Arial, Helvetica, sans-serif">COIL
DESIGN</font></strong></div></td>
<td><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PARAMETERS</strong></font></td>
<td> </td>
</tr>
<tr>
<td align=right> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right><b>Primary Resistance (ohms)</b></td>
<td><input type=text name=Pres size=25></td>
<td><div align="right"><b>Primary Inductance (mH)</b></div></td>
<td><input type=text name=Pind size=25></td>
</tr>
<tr>
<td align=right><b>Secondary Resistance (ohms)</b></td>
<td><input type=text name=Sres size=25></td>
<td><div align="right"><b>Secondary Inductance (H)</b></div></td>
<td><input type=text name=Sind size=25></td>
</tr>
<tr>
<td align=right> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right><b>Peak Operating Current (Amps)</b></td>
<td><input type=text name=POC size=25></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right><b>Output Energy (mJ)</b></td>
<td><input type=text name=Egy size=25></td>
<td><div align="right"><b>Output Voltage (kV)</b></div></td>
<td><input type=text name=Volt size=25></td>
</tr>
<tr>
<td align=right> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right><b># HV Towers per Coil</b></td>
<td><input type=text name=TPC size=25></td>
<td><div align="right"><b># of Coils per Package</b></div></td>
<td><input type=text name=CPP size=25></td>
</tr>
<tr>
<td align=right> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align=right> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th colspan=4><b>Please enter any additional information here:</b></th>
</tr>
<tr>
<th colspan=4><textarea name=Mess cols=50 rows=10 id="Message"></textarea></th>
</tr>
</table>
</dl>
<div align="center">
<p>
<input type=hidden name=BodyTag value="<body bgcolor="#484589" text="#FFFFFF" link="#FFFF00" alink="#FFFFFF" vlink="#FF7F00">">
<input type=hidden name=FA value=SendMail>
</p>
<p><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PLEASE MAKE SURE ALL
INFORMATION<br>
IS CORRECT BEFORE SUBMITTING</strong></font></p>
<p>
<input type=submit value="Submit Form">
</p>
</div>
</form>
THE FILE THAT PROCESSES THE FORM DATA (formdata.php)
***********************************************
<?php
$con = mysql_connect("localhost","XXX","XXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("customform", $con);
$sql="INSERT INTO formdata (Fname, Lname, Title, Comp, Addr, City, SProv, Ctry, ZPC, Tel, Fax, Email, EAV, Appl, Syst, Pres, Pind, Sres, Sind, POC, Egy, Volt, TPC, CPP, Mess)
VALUES ('$_POST[Fname]','$_POST[Lname]','$_POST[Title]','$_POST[Comp]','$_POST[Addr]','$_POST[City]','$_POST[SProv]','$_POST[Ctry]','$_POST[ZPC]','$_POST[Tel]','$_POST[Fax]','$_POST[Email]','$_POST[EAV]','$_POST[Appl]','$_POST[Syst]','$_POST[Pres]','$_POST[Pind]','$_POST[Sres]','$_POST[Sind]','$_POST[POC]','$_POST[Egy]','$_POST[Volt]','$_POST[TPC]','$_POST[CPP]','$_POST[Mess]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your Information Was Successfully Posted";
mysql_close($con);
$to = "recipient email address here";
$subject = "Custom Form";
$email = $_POST['Email'] ;
$message = $_POST['Comp'] ;
$headers = "From: $Email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>