I wrote a script that will take data and post it to a database no problem, but at the same time I need the data to be emailed to two different email addresses and I never get an email. My code looks pretty solid and I am not sure what else to do since it brings me to my success page but I still don't get an email. (I changed the email address for security so they are real emails). Any idea's? Thanks.
<?php
function post_to_db() {
$conn = mysql_connect("db2401.snip.net", "dbo328063853", "idirect2");
mysql_select_db("db328063853", $conn);
if (!$_POST['fname'] | !$_POST['lname'] | !$_POST['addr1'] | !$_POST['city'] | !$_POST['state'] | !$_POST['zip'] | !$_POST['phone1'] | !$_POST['email'] | !$_POST['dob'] | !$_POST['esttotal']) {
die('ERROR: You left a field blank! Go back and try again');
}
$fname = mysql_real_escape_string ($_POST['fname']);
$lname = mysql_real_escape_string ($_POST['lname']);
$addr1 = mysql_real_escape_string ($_POST['addr1']);
$city = mysql_real_escape_string ($_POST['city']);
$state = mysql_real_escape_string ($_POST['state']);
$zip = mysql_real_escape_string ($_POST['zip']);
$phone1 = mysql_real_escape_string ($_POST['phone1']);
$email = mysql_real_escape_string ($_POST['email']);
$dob = mysql_real_escape_string ($_POST['dob']);
$esttotal = mysql_real_escape_string ($_POST['esttotal']);
$ip=$_SERVER['REMOTE_ADDR'];
global $fname, $lname, $addr1, $city, $state, $zip, $phone1, $email, $dob, $esttotal, $ip;
$sql="INSERT INTO form_data (fname, lname, addr1, city, state, zip, phone1, email, dob, esttotal, ip)
VALUES
('$fname','$lname','$addr1','$city','$state','$zip','$phone1','$email','$dob','$esttotal','$ip')";
if (!mysql_query($sql,$conn))
{
die('Error: ' . mysql_error());
}
}
post_to_db();
mysql_close($conn);
function emailAll() {
function checkEmail($email) {
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {return false;}
return true;
}
$_ip=$_SERVER['REMOTE_ADDR'];
if(isset($_POST["submitForm"])){
$_fname = ($_POST["fname"]);
$_lname = ($_POST["lname"]);
$_addr1 = ($_POST["addr1"]);
$_city = ($_POST["city"]);
$_state = ($_POST["state"]);
$_zip = ($_POST["zip"]);
$_phone1 = ($_POST["phone1"]);
$_email = ($_POST["email"]);
$_dob = ($_POST["dob"]);
$_esttotal = ($_POST["esttotal"]);
$_body = "Message has been sent from data collection form\n\n";
$_subject = "E-Mail from your web form";
if($_fname){
$_body .= "First Name: $_fname\n\n";
}
if($_lname){
$_body .= "Last Name: $_lname\n\n";
}
if($_addr1){
$_body .= "Address 1: $_addr1\n\n";
}
if($_city){
$_body .= "City: $_city\n\n";
}
if($_state){
$_body .= "State: $_state\n\n";
}
if($_zip){
$_body .= "Zip Code: $_zip\n\n";
}
if($_phone1){
$_body .= "Phone 1: $_phone1\n\n";
}
if($_email){
$_body .= "Email Address: $_email\n\n";
}
if($_dob){
$_body .= "Date of Birth: $_dob\n\n";
}
if($_esttotal){
$_body .= "Estimated Total: $_esttotal\n\n";
}
if($_ip){
$_body .= "IP Address of User: $_ip\n\n";
}
$_to = array();
//get recipients
$_to[] = "name@email.com" . ", ";
$_to[] .= "name@email.com";
//set the headers
$headers = "From: <name@domain.com>";
mail($_to[$i], $_subject, $_text, $_headers);
}
}
emailAll();
header('Location: success.html');
?>