The following code sends me an email holding the following variables. One of the last if statements says if(mail) then echo "You will be contacted soon". When the script runs I get echoed back "You will be contacted soon", however, I never receive an email.
I do have a smaller contact script (posted after this first and larger one) that does work.
Note: contants.php and functions.php are both included and work fine WEBMASTER_EMAIL is defined in contanstants.php and is correct, because my smaller contact script uses the same variable, and emails me fine.
Thanks for the help
<?php
// pull constant variables
include("php/constants.php");
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post) {
include ("php/functions.php");
}
// general info
$name = stripslashes($_POST['contact']);
$phone = $_POST['phone'];
$email = trim($_POST['email']);
$time_to_reach = $_POST['time-to-reach']; // what the best time to reach them?
// delivery info
$delivery_address = $_POST['del-address'];
$delivery_city = $_POST['del-city'];
$delivery_state = $_POST['del-state'];
$delivery_zip = $_POST['del-zip'];
// moving city info if applicable
$moving_address = $_POST['move-address'];
$moving_city = $_POST['move-city'];
$moving_state = $_POST['move-state'];
$moving_zip = $_POST['move-zip'];
// date needed
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
// how long do you need the storage?
$storage_length = $_POST['time-length'];
// how many containers do you need?
$quantity_containers = $_POST['number-of-containers'];
// how did you hear about us?
$tracker = $_POST['tracker'];
// message
$message_holder = htmlspecialchars($_POST['message']);
$error = '';
// check general info
if(!$name) { $error .= 'Please enter your name.<br />'; }
if(!$email) { $error .= 'Please enter an e-mail address.<br />'; }
if($email && !ValidateEmail($email)) { $error .= 'Please enter a valid e-mail address.<br />'; }
if(!$time_to_reach) { $error .= 'Please select the best time to reach you.<br />'; }
// check delivery info
if(!$delivery_address) { $error .= 'Please enter you current address.<br />'; }
if(!$delivery_city) { $error .= 'Please enter your current city.<br />'; }
if(!$delivery_state) { $error .= 'Please enter your current state.<br />'; }
if(!$delivery_zip) { $error .= 'Please enter your current zip code.<br />'; }
// check date needed
if(!$month) { $error .= 'Please enter the approximate date you need the storage.<br />'; }
if(!$day) { $error .= 'Please enter the approximate date you need the storage.<br />'; }
if(!$year) { $error .= 'Please enter the approximate date you need the storage.<br />'; }
// check length of time needed
if(!$storage_length) { $error .= 'Approximatly how long will you need the storage unit for?<br />'; }
// check quantity of storages
if(!$quantity_containers) { $error .= 'How many containers will you need?<br />'; }
// check advertising tracker
if(!$tracker) { $error .= 'Please let us know how you\'ve heard of us.<br />'; }
// check message (length)
if(!$message_holder || strlen($message_holder) < 10) {
$error .= "Please enter your message. It should have at least 10 characters.<br />";
}
// build email message
$message = "Name: {$name}
Phone: {$phone}
Email: {$email}
Best time to reach: {$time_to_reach}\n
-----------------------------------------------------
Delivery address: {$delivery_address}
{$delivery_city}, {$delivery_state} {$delivery_zip}
Moving address: {$moving_address}
{$moving_city}, {$moving_state} {$moving_zip}
-----------------------------------------------------
Date needed: {$month}/{$day}/{$year}
Length of time needed: {$storage_length}
Number of containers: {$quantity_containers}
Where did you hear about us?
{$tracker}\n
Message: {$message_holder}\n";
if(!$error) {
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: [email protected]\r\n"
."Reply-To: ".$name."<".$email.">\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail) {
echo '<p>Thank you, you will be contacted soon.</p>';
}
} else {
echo '<div class="notification_error">'.$error.'</div>';
}
?>
The following script, contact script, does work meaning I receive an email.
<?php
// pull constant variables
include("php/constants.php");
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post) {
include ("php/functions.php");
}
// variables
$name = stripslashes($_POST['name']);
$phone = $_POST['phone'];
$email = trim($_POST['email']);
$tracker = $_POST['tracker'];
$message_holder = htmlspecialchars($_POST['message']);
$error = '';
// check name
if(!$name) {
$error .= 'Please enter your name.<br />';
}
// check email
if(!$email) {
$error .= 'Please enter an e-mail address.<br />';
}
// validate email
if($email && !ValidateEmail($email)) {
$error .= 'Please enter a valid e-mail address.<br />';
}
// check advertising tracker
if(!$tracker) {
$error .= 'Please let us know how you\'ve heard of us.';
}
// check message (length)
if(!$message_holder || strlen($message_holder) < 10) {
$error .= "Please enter your message. It should have at least 10 characters.<br />";
}
// build email message
$message = "Name: {$name} \n
Phone: {$phone} \n
Email: {$email} \n
Where did you hear about us?
{$tracker}\n\n
Message: {$message_holder}\n";
if(!$error) {
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: [email protected]\r\n"
."Reply-To: ".$name."<".$email.">\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail) {
//header("Location: thank_you.php");
echo "Thank you. You will be contacted soon.";
}
} else {
echo '<div class="notification_error">'.$error.'</div>';
}
?>