I have this code to put the information from my contact page into a data base and also send an email to me telling me someone filled out the contact page. Here is my the code for my PHP page.
<?php
$con = mysql_connect("localhost","myusername","xxxmypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database name", $con);
$sql="INSERT INTO table name (id, first_name, last_name, address, city, state, zip, area, exchange, phone, email_info, contact, services, comments)
VALUES
('$_POST[id]','$_POST[first_name]','$_POST[last_name]','$_POST[address]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[area]','$_POST[exchange]','$_POST[phone]','$_POST[email_info]','$_POST[contact]','$_POST[services]','$_POST[comments]' )";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
include_once("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Username = "myusername@gmail.com";
$mail->Password = "mypassword@gmail.com";
$mail->AddAddress("to email");
$mail->From = "Joe.K.Doe@gmail.com";
$mail->FromName = $_POST['name'];
$mail->Subject = "John someone has filled out your contact page!";
$mail->IsHTML(true);
$mail->Body =$_POST['comments'].'First Name: '. $_POST['first_name' ].'Last Name: '. $_POST['last_name'].'Address: '.$_POST['address'].'City: '.$_POST['city'].'State: '.$_POST['state'].'Zip: '.$_POST['zip'].'Area: '.$_POST['area'].'Exchange: '.$_POST['exchange'].'Phone: '.$_POST['phone'].'Email Info: '.$_POST['email_info'].'Contact: '.$_POST['contact'].'Services: '.$_POST['services'];
if($mail->Send()) {
echo "Thank you for contacting Us! We will get back to you as soon as possible!";
}
?>
and this is what the email looks like
I am ready to get this finished it has been a great chance to learn. First Name: JohnLast Name: DoeAddress: 21 WAWA Ave.City: ChicagoState: ILZip: 564883Area: 689Exchange: 675Phone: 9878Email Info: John@gmail.comContact: emailServices: babbitt bearings
see how all the words like First Name: JohnLast Name: DoeAddress: is all crammed together and it is hard to tell what starts where and what end where. I tried
between the $POST but that did not work. All comments greatly appreciated. Codin