Hello All:
I have a mail script which I have been piecing together for most of the afternoon but for some reason when I hit submit, the page just reloads to the top as if I have a # in an href or something.
Ihave the display errors uncommented but I do not get any errors so I have no clue as to what I am looking for in this case.
Can someone tell me what I did wrong here?
<?php
// Uncomment the two following lines to test and display errors. Once complete, comment out again.
ini_set ('display_errors', 'On');
error_reporting (E_ALL);
include ('includes/email_validate.inc'); // Include custom email validation script
// Create a function for escaping data
function escape_data($data) {
global $dbc; // Need the connection.
if (ini_get('magic_quotes_gpc')) { // Check if Magic Quotes Enabled.
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
} // End of function.
// Set valid domain host and http server values. Added all variations of valid domains in array
$valid_hosts = array ('kardwellwholesale.com', 'www.kardwellwholesale.com');
$errors = '';
$user_data = array();
$user_data['host'] = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$user_data['ip'] = $_SERVER['REMOTE_ADDR'];
$user_data['agent']= $_SERVER['HTTP_USER_AGENT'];
if (isset($_SERVER['HTTP_REFERER'])) {
$user_data['ref'] = $_SERVER['HTTP_REFERER'];
} else {
$user_data['ref'] = '';
}
$user_data['time'] = date("D M j G:i:s Y");
if (isset($_POST['']) && ($_POST['submit'] == 'Submit')) { // Handle the form.
$message = NULL; // Create a new empty variable.
// Check for a Business Name.
if (empty($_POST['bussiness_name']) || !valid_string($_POST['bussiness_name'])) {
$First_Name = FALSE;
$message .= 'Please enter your Business Name!<br>';
} else {
$First_Name = $_POST['bussiness_name'];
}
if (empty($_POST['First_Name']) || !valid_string($_POST['First_Name'])) {
$First_Name = FALSE;
$message .= 'Please enter your first name!<br>';
} else {
$First_Name = $_POST['First_Name'];
}
if (empty($_POST['Last_Name']) || !valid_string($_POST['Last_Name'])) {
$Last_Name = FALSE;
$message .= 'Please enter your last name!<br>';
} else {
$Last_Name = $_POST['Last_Name'];
}
// Check for a Street Address.
if (empty($_POST['Address_Line']) || !valid_string($_POST['Address_Line'])) {
$Address_Line = FALSE;
$message .= 'Please enter your Street Address!<br>';
} else {
$Address_Line = $_POST['Address_Line'];
}
// Check for a City.
if (empty($_POST['City']) || !valid_string($_POST['City'])) {
$City = FALSE;
$message .= 'Please enter your City!<br>';
} else {
$City = $_POST['City'];
}
// Check for a State/Province.
if (empty($_POST['State']) || !valid_string($_POST['State'])) {
$State = FALSE;
$message .= 'Please enter your State/Province!<br>';
} else {
$State = $_POST['State'];
}
// Check for a Zip/Postal Code.
if (empty($_POST['Postal_Code']) || !valid_string($_POST['Postal_Code'])) {
$Postal_Code = FALSE;
$message .= 'Please enter your Postal Code!<br>';
} else {
$Postal_Code = $_POST['Postal_Code'];
}
// Check for a Country.
if (empty($_POST['Country']) || !valid_string($_POST['Country'])) {
$Country = FALSE;
$message .= 'Please select a Country!<br>';
} else {
$Country = $_POST['Country'];
}
// Check for a Email.
if (empty($_POST['email']) || !valid_string($_POST['email'])) {
$Country = FALSE;
$message .= 'Please Enter an Email!<br>';
} else {
$Country = $_POST['email'];
}
if ($business_name && $First_Name && $Last_Name && $Address_Line && $City && $State && $Postal_Code && $Country && $email) {
if($email == ""){
// If eveything is OK.
// Send an email, if desired.
$recipient_email = 'paul@kardwell.com'; // to add more to this list just add a comma and then the next email address, e.g. 'catalogrequest@kardwell.com, email1@email.com, email2@email.com, email3@email.com'
$headers = 'MIME-Version: 1.0' . "\\r\
\
\
";
$headers .= 'Content-type: text/plain; utf-8' . "\\r\
\
\
";
$headers .= 'From: Catalog Request <catalogrequest@kardwell.com>' . "\\r\
\
\
";
$headers .= 'Return-Path: catalogrequest@kardwell.com' . "\\r\
\
\
";
$body = 'Submit Date Time: ' . $user_data['time'] . "\\r\
\
\
";
$body .= 'The following registration request was submitted from ' . $_SERVER['HTTP_HOST'] . "\\r\
\
\
";
$body .= 'Business Name: ' . stripslashes(htmlspecialchars($business_name)) . "\\r\
\
\
";
$body .= 'Name: ' . stripslashes(htmlspecialchars($First_Name)) . " " . stripslashes(htmlspecialchars($Last_Name)) . "\\r\
\
\
";
$body .= 'Street: ' . stripslashes(htmlspecialchars($Address_Line)) . "\\r\
\
\
";
$body .= 'City: ' . stripslashes(htmlspecialchars($City)) . "\\r\
\
\
";
$body .= 'State: ' . stripslashes(htmlspecialchars($State)) . "\\r\
\
\
";
$body .= 'Postal Code: ' . stripslashes(htmlspecialchars($Postal_Code)) . "\\r\
\
\
";
$body .= 'Country: ' . stripslashes(htmlspecialchars($Country)) . "\\r\
\
\
";
$body .= 'Email: ' . stripslashes(htmlspecialchars($email)) . "\\r\
\
\
";
$body .= 'Host: ' . $user_data['host'] . "\\r\
\
\
";
$body .= 'IP: ' . $user_data['ip'] . "\\r\
\
\
";
$body .= 'Remote Agent: ' . $user_data['agent'] . "\\r\
\
\
";
$body .= 'Referrer: ' . $user_data['ref'] . "\\r\
\\r\
\
\
";
$body .= "Sincerely,\\r\
\
\
Kardwell International";
mail ($recipient_email, 'Registration Request from KardwellWholesale.com', $body, $headers);
$message = 'Your registration request was successfully delivered!<br>Thank you for contacting KardwellWholesale.com.';
} else {
$_SESSION['business_name'] = $_POST['business_name'];
$_SESSION['First_Name'] = $_POST['First_Name'];
$_SESSION['Last_Name'] = $_POST['Last_Name'];
$_SESSION['Address_Line'] = $_POST['Address_Line'];
$_SESSION['City'] = $_POST['City'];
$_SESSION['State'] = $_POST['State'];
$_SESSION['Postal_Code'] = $_POST['Postal_Code'];
$_SESSION['Country'] = $_POST['Country'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['$SUBMIT'] = $_POST['$SUBMIT'];
?>
<?php
}
} else { // If it did not run OK.
$message .= '<p><font color="red">Sorry! Your Registration did not go through, please call 1-800-233-0828.</font></p>';
}
} // End of the main Submit conditional.
?>
The form action is set to
action=“<?=‘https://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’] ?>”
Thanks for any help or advice on this one.
Paul