Hi, thank you for taking the time to look at this. I am having a problem getting a simple emailer to work properly. I know I don’t have any php.ini issues, because I did get a sample script to work. I’m not sure what I’m missing here, and I’ve gone around with it for a while. I’m thinking it’s something simple. Thanks again!
The page containing the form:
[code]
CW Courier - Quotereceive price quote (all fields required)
First & Last Name * | |
Telephone Number * | |
Email Address * | |
City and State of Pickup * | |
City and State of Delivery * | |
Description of Shipment * | |
Dimensions & Weight * | |
Date and Time of Delivery * | |
Delivery Time is * | Flexible Mandatory |
Copyright 2012, Tharsis Media. All rights reserved.
The PHP script:
[php]<?php
if(isset($_POST[‘email’])) {
// set email destination and subject line.
$email_to = "[email protected]";
$email_subject = "CWCourier.com Price Quote Request";
function died($error) {
// error display code
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation that expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['telephone']) ||
!isset($_POST['email']) ||
!isset($_POST['from_city']) ||
!isset($_POST['to_city']) ||
!isset($_POST['description']) ||
!isset($_POST['dimensions']) ||
!isset($_POST['delivery_time'])) {
died('There appears to be missing information in the form you submitted. Please go back and supply all required information so that we can supply your quote as accurately as possible.');
}
$name = $_POST['name']; // required
$telephone = $_POST['telephone']; // required
$email_from = $_POST['email']; // required
$from_city = $_POST['from_city']; // required
$to_city = $_POST['to_city']; // required
$description = $_POST['description']; // required
$dimensions = $_POST['dimensions']; // required
$delivery_time = $_POST['delivery_time']; // required
$flexible = $_POST['flexible']; // automatic
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= ‘The Email Address you entered does not appear to be valid.
’;
}
$string_exp = “/^[A-Za-z .’-,]+$/”;
if(!preg_match($string_exp,$name)) {
$error_message .= ‘The name you entered does not appear to be valid.
’;
}
if(!preg_match($string_exp,$from_city) || !preg_match($string_exp,$to_city)) {
$error_message .= ‘A city you entered does not appear to be valid.
’;
}
if(strlen($description) < 2) {
$error_message .= ‘The description you entered does not appear to be valid.
’;
}
if(strlen($dimensions) < 2) {
$error_message .= ‘The dimensions you entered do not appear to be valid.
’;
}
if(strlen($delivery_time) < 2) {
$error_message .= ‘The delivery time you entered does not appear to be valid.
’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Quote request details:\n\n”;
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Phone: ".clean_string($telephone)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Pickup City: ".clean_string($from_city)."\n";
$email_message .= "Delivery City: ".clean_string($to_city)."\n";
$email_message .= "Description of Shipment: ".clean_string($description)."\n";
$email_message .= "Dimensions & Weight: ".clean_string($dimensions)."\n";
$email_message .= "Date and Time of Delivery: ".clean_string($delivery_time)."\n";
$email_message .= "Delivery Time is (Flexible or Mandatory): ".clean_string($flexible)."\n";
// create email headers
$headers = 'From: '.“[email protected]\r\n”.
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’.phpversion();
if (mail($email_to, $email_subject, $email_message, $headers)) {
echo(“
Message delivery failed, please go back and try again.
”);} else {
?> CW Courier - Quote
Thank you
Thank you for requesting a price quote with CW Courier. We will look over your requirements immediately and get back to you. Good day!Copyright 2012, Tharsis Media. All rights reserved.