can someone read through this script really quick and verify that I didn't miss anything... I'm not getting any errors in my IDE so just have to make sure the structure is correct
<?php
require_once '/usr/local/cpanel/3rdparty/lib/php/Mail.php';
$db_server = 'localhost';
$db_user = '-----';
$db_pass = '-----';
$dbc = mysql_connect ($db_server, $db_user, $db_pass);
if (!$dbc) {
die(mysql_error());
header ('Location: /contact');
exit;
}
if ($_POST['contactsent'] != 'yes') {
header ('Location: /contact');
exit;
} else {
if (is_array($_POST)) {
foreach ($_POST as $key => $value) {
$_POST[$key] = mysql_real_escape_string(stripslashes($value));
}
}
$RequestType = $_POST["RequestType"];
$ConsumerBusiness = $_POST["ConsumerBusiness"];
$GlobalLocation = $_POST["GlobalLocation"];
$FirstName = strtolower(str_replace("'","''",$_POST["FirstName"]));
$FirstName = strtoupper(substr($FirstName,0,1)).substr($FirstName,1);
$LastName = strtolower(str_replace("'","''",$_POST["LastName"]));
$LastName = strtoupper(substr($LastName,0,1)).substr($LastName,1);
$Email = strtolower(str_replace("'","''",$_POST["Email"]));
$Title = strtolower(str_replace("'","''",$_POST["Title"]));
$Title = strtoupper(substr($Title,0,1)).substr($Title,1);
$Company = strtolower(str_replace("'","''",$_POST["Company"]));
$Company = strtoupper(substr($Company,0,1)).substr($Company,1);
$Address = strtolower(str_replace("'","''",$_POST["Address"]));
$Address = strtoupper(substr($Address,0,1)).substr($Address,1);
$City = strtolower(str_replace("'","''",$_POST["City"]));
$City = strtoupper(substr($City,0,1)).substr($City,1);
$State = $_POST["State"];
$Zip = $_POST["Zip"];
$Phone = $_POST["Phone"];
$F = $_POST["F"];
$ProductDesc = $_POST["ProductDesc"];
$Comment = $_POST["Comment"];
if ($GlobalLocation == "Canada"):
$SendTo="canadainfo@------.com";
elseif ($GlobalLocation == "Central America"):
$SendTo="customer.service@------.com.pa";
elseif ($GlobalLocation == "Europe"):
$SendTo="marketing@-----.uk";
elseif ($GlobalLocation == "Mexico"):
$SendTo="ventas@------.com.mx";
else:
$SendTo="info@------.com";
endif;
function dbSet($fields, $source = array()) {
$set='';
if (!source) $source = &$_POST;
foreach ($fields as $field) {
if (isset($source[$field])) {
$set.="`$field`='".mysql_real_escape_string($source[$field])."', ";
}
}
return substr($set, 0, -2);
}
// INSERT INTO DATABASE
mysql_select_db("new_contact",$dbc) or die("Could not select new_contact");
$fields = explode(" ", "RequestType ConsumerBusiness GlobalLocation FirstName LastName Email Title Company Address City State Zip Phone F ProductDesc Comment");
$query = "INSERT INTO new_contact SET ".dbSet($fields, $_POST);
mysql_query($query);
// SETUP EMAIL
$Bodycopy = "This information was submitted via the ------.com website and sent to you because of the location
identified by the user. <br>If this has reached you in error, please forward this email to info@------.com";
$Bodycopy. "<br>----------------------------------------------------------------------------------------------<br><br>";
if ($RequestType != "") $Bodycopy. "What kind of information do you need? : " .$RequestType. "<br>";
if ($ConsumerBusiness != "") $Bodycopy. "What type of customer or vendor are you? : " .$ConsumerBusiness. "<br>";
if ($GlobalLocation != "") $Bodycopy. "Global Location : " .$GlobalLocation. "<br>";
if ($Company != "") $Bodycopy. "Company : " .$Company. "<br>";
if ($FirstName != "") $Bodycopy. "First Name : " .$FirstName. "<br>";
if ($LastName != "") $Bodycopy. "Last Name : " .$LastName. "<br>";
if ($Title != "") $Bodycopy. "Title : " .$Title. "<br>";
if ($Email != "") $Bodycopy. "Email : " .$Email. "<br>";
if ($Address != "") $Bodycopy. "Address : " .$Address. "<br>";
if ($City != "") $Bodycopy. "City : " .$City. "<br>";
if ($State != "") $Bodycopy. "State : " .$State. "<br>";
if ($Zip != "") $Bodycopy. "Zip/Postal Code : " .$Zip. "<br>";
if ($Phone != "") $Bodycopy. "Phone : " .$Phone. "<br>";
if ($F != "") $Bodycopy. "F : " .$F. "<br>";
if ($ProductDesc != "") $Bodycopy. "UPC or product description : " .$ProductDesc. "<br>";
$Bodycopy. "<br>----------------------------------------------------------------------------------------------<br><br>";
if ($Comment != "") $Bodycopy. "Comments : <br>" .$Comment. "<br>";
$Bodycopy. "<br><br>";
$Bodycopy. $IP = $_SERVER["remote_addr"];
// PROCESS EMAIL
// mail server info...
$from = $SendTo;
$to = "Do Not Reply <donotreply@------>";
$subject = "Website Contact : " . $GlobalLocation;
$body = $Bodycopy;
$host = "mail.------";
$port = "25";
$username = "donotreply@-------";
$password = "-------";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'port' => $port,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
// MAKE SURE DB CONN IS CLOSED
mysql_close($dbc);
// REDIRECT TO THANK YOU PAGE
header ('Location: /index.php?option');
exit();
}
?>