Contact form not working

Hi,
I am new to PHP so please forgive …

I am trying to send Name, Email and Company in a contact form to an email address.FYI - I am utilizing a DW template.

The contact form here: [code]

#wrapper #header .quote p { color: #FFFFFF; } Surplus Steel & Supply - Metals, Industrial Supplies and Plastics

Call Us

407-293-5788
800-299-5788

SURPLUS STEEL & SUPPLY

Your one-stop metal supplier since 1980

Newsletter Signup

Sign up to receive our monthly newsletter which will showcase new arrivals,
special offers and industry news right to your inbox.

 

 

    </table>

  
  </form>

<p></p>


</div>

© 2013 Surplus Steel & Supply®. All rights reserved.     Site by: Multimedia Elements

[/code]

should re-direct to the Thank You page here:

[code]

#wrapper #header .quote p { color: #FFFFFF; } Surplus Steel & Supply - Metals, Industrial Supplies and Plastics

Call Us

407-293-5788
800-299-5788

SURPLUS STEEL & SUPPLY

Your one-stop metal supplier since 1980

<?php

if(isset($_POST[‘email’])) {

// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "[email protected]";

$email_subject = "SSS Newsletter Signup Request";

 

 

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['name']) ||

    !isset($_POST['company']) ||

    !isset($_POST['email'])) {

    died('We are sorry, but there appears to be a problem with the form you submitted.');       

}

 

$first_name = $_POST['name']; // required

$last_name = $_POST['company']; // required

$email_from = $_POST['email']; // 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.<br />';

}

if(!preg_match($string_exp,$last_name)) {

$error_message .= 'The Name you entered does not appear to be valid.<br />';

}

if(strlen($error_message) > 0) {

died($error_message);

}

$email_message = "Surplus-Steel Newsletter signup details below.\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 .= "Email: ".clean_string($email_from)."\n";

$email_message .= "Company: ".clean_string($company)."\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);

?>

<!-- include your own success html here -->
<div id="main">

  Thank you for subscribing to our newsletter.</span></h1></div>
<?php } ?>

© 2013 Surplus Steel & Supply®. All rights reserved.     Site by: Multimedia Elements

[/code]

The problems:

[ol][li]The Thank You page is blank[/li]
[li]The email is never received[/li][/ol]

Also wanted to see if anyone can tell me how to get the re-captcha validating like the other fields (it should be required in order to submit)

Thanks in advance!

D

*Name Your name is required.
*Email Your email is required.Invalid email format.
Company
 
 

Okay, where to start… Not really sure. First you have a contact form called something.
This is the first page you showed to us. It has a form on it. This form is defined as:

Therefore, once the user fills in the inputs and presses your submit button it goes to the file named "send_form_email.php" which I will guess is the second file. If you look at that code, you check to see if the email is set. If not, nothing happens... But, you never check if the submit button was pressed. You just check for the email. Your code is very mixed up. Hard to follow. First, all functions should be set before any PHP code. Functions can be placed into If clauses, but, not a good practice. Your many validations are complex and duplicated. Very nonstandard in my opinion. Also, you suppress the mail function's error reporting. Never use the suppression of errors. That does not help. Remove the " @ " at the beginning of the mail function and retry. See if you get an error. Another problem is that your error system is really a big problem. If one of your validations do not work out, it calls a "dies()" code function which displays a message and then stops the page from processing further. This will end the page with no way back. The site dies. It would be much better to create a string with the errors appended to it as they are found and then if it is empty, mail it if not empty display the error with the rest of the page still there with a return button to the contact page. make a website DIE during it's use is quite silly!

So, lots to do to make it correct. First, move all your functions to right after the <?PHP tag and remove the
error suppression from the mail() function. ( @ ) And, retest and let us know. Repost your code and we
can help you figure the rest out…

Sponsor our Newsletter | Privacy Policy | Terms of Service