PHP Customer Form Help

Hi I am working on a contact form…
Not sure why its not working this is my first PHP form…

everything looks right but it doesn’t work, can some one take a look please.

thanks
Heres the HTML code
HTML Code:

[code]

Business Name*
Contact Name*
Address*
City*
State*
Zip*
Email Address*
Telephone Number*
Fax*
Website*
How Many Locations do you operate and where are they located?*
What other brands do you carry?*
Please tell us more about your business and why your interested in becoming a our dealer.*
[/code]

Heres the PHP code

PHP Code:

[code]<?php
if(isset($_POST[‘email’])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "DEALER INQUIRY";
 
 
function died($error) {
    // your error code can go here
    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 expected data exists
if(!isset($_POST['Business_name']) ||
    !isset($_POST['Contact_name']) ||
    !isset($_POST['Address']) ||
    !isset($_POST['City']) ||
    !isset($_POST['State']) ||
    !isset($_POST['Zip']) ||
    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['Fax']) ||
    !isset($_POST['Locations']) ||
    !isset($_POST['Brands']) ||
    !isset($_POST['Tell'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');       
}
 
$Business_name = $_POST['Business_name']; // required
$Contact_name = $_POST['Contact_name']; // required
$Address = $_POST['Address']; // required
$City = $_POST['City']; // required
$State = $_POST['State']; // required
$Zip = $_POST['Zip']; // required
$email = $_POST['email']; // required
$telephone = $_POST['telephone']; // required
$Fax = $_POST['Fax']; // required
$Locations = $_POST['Locations']; // required
$Brands = $_POST['Brands']; // required
$Tell = $_POST['Tell']; // required

 
$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,$Business_name)) {
$error_message .= ‘The Business Name you entered does not appear to be valid.
’;
}
if(!preg_match($string_exp,$Contact_name)) {
$error_message .= ‘The Contact Name you entered does not appear to be valid.
’;
}
if(strlen($Tell) < 2) {
$error_message .= ‘The Comments you entered do not appear to be valid.
’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\n\n”;

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}
 
$email_message .= "Business Name: ".clean_string($Business_name)."\n";
$email_message .= "Contact Name: ".clean_string($Contact_name)."\n";
$email_message .= "Address: ".clean_string($Address)."\n";
$email_message .= "City: ".clean_string($City)."\n";
$email_message .= "State: ".clean_string($State)."\n";
$email_message .= "Zip: ".clean_string($Zip)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($Telephone)."\n";
$email_message .= "Fax: ".clean_string($Fax)."\n";
$email_message .= "Locations: ".clean_string($Locations)."\n";
$email_message .= "Brands: ".clean_string($Brands)."\n";
$email_message .= "Tell: ".clean_string($Tell)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

Thank you for contacting us. We will be in touch with you very soon.
We will now redirect you to our Home Page.

<?php } ?>[/code]

Hey there,

I didn’t have time to check your preg match, but before we even go there, you have a mismatch in your form.

Take a look at your label Locations. In the textarea, you are trying to submit the textarea by the name comments but your send_form_email.php is expecting the input by the name Locations.

Another thing would be your last textarea. The name of it is comments but your send_form_email.php is expecting the input by the name Tell.

So change whichever, either the html or php file. Just make sure its a match.

Regards,
developer.dex2908

Wonderful, it works now, the last thing that I see is that it is saying that the email is invalid….

I tried removing the code that doesn’t allow invalid emails and it works however emails come in blank even when it was entered…

Hi akjemiolo,

Try changing this…[php]$email = $_POST[‘email’]; // required[/php]
to …[php]$email_from = $_POST[‘email’]; // required[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service