0

I have a php email script that has worked with a website used it on before, but I've moved it over to the re-designed site and when I hit submit the page reloads with this additional text in the url:

?name=Lee+Thomas&email=leethomas%40corwenforestry.co.uk&message=message&Submit=Send

Here's the form in the contact.html page:

<form name="contact" method="post" action="sendmail.php">
 <table border="0" align="center" cellpadding="0" cellspacing="1">
  <tr>
   <td>
    <input name="name" placeholder="Name" type="text" id="name" size="50">
   </td>
  </tr>
  <tr>
   <td>
    <input name="email" placeholder="Email" type="text" id="email" size="50">
   </td>
  </tr>
  <tr>
   <td>
    <textarea name="message" placeholder="Message" cols="50" rows="4" id="message">
    </textarea>
   </td>
  </tr>
  <tr>
   <td>
     <input type="submit" name="Submit" value="Send"> <input type="reset" name="Reset" value="Reset">
   </td>
  </tr>
 </table>
</form>

And here's the sendmail.php script:

<?php
if(isset($_POST['email'])) {
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "CFR F3 Contact Form";


    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['email']) ||
        !isset($_POST['message'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $message = $_POST['message']; // 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 />';
  }
$string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$name)) {
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
  }
  }
  if(strlen($message) < 2) {
    $error_message .= 'The Message you entered do not appear to be valid.<br />';
  }
  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 .= "Name: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Message: ".clean_string($message)."\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 CF Racing F3, we will be in touch with you very soon.

<?php
?>

Can anyone tell me where I'm going wrong here?

[EDIT] The problem in block quotes below is now solved, the reset button does exactly that.

Another issue I'm having is that the Reset button is acting as another Submit/Send button, is there a way I can have the Submit/Send button act as that button?

Thanks in advance for your help.

[EDIT] Changed the html to remove redundant form tag.

1
  • Remove the <form> tag inside the <table>. Commented Dec 6, 2012 at 11:09

3 Answers 3

2

there is tow <form> tag try after remove one stray <form> tag

use this

  <form name="contact" method="post" action="sendmail.php">
   <table border="0" align="center" cellpadding="0" cellspacing="1">

instead of

<form>
 <table border="0" align="center" cellpadding="0" cellspacing="1">
  <form name="contact" method="post" action="sendmail.php">
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, I missed that. Now I get the success message but no email sent to the mentioned account. I also put the proper form tag before the form, for css reasosns, thought I'd let you know if that makes any difference
it also depends on hosting ..if you have shared it take up to 10 -20 minutes ..so please wait some time even than if not get mail than leave a comment
No still no email, and it's gmail I'm using to test and every other time I've tested it and it's worked, it's arrived within a minute.
Ahh balls. My bad, I uploaded it on to a staging part of a live server and it worked. WAMP must be mis-configured to send emails via PHP.
0

Remove top <form> tag, you have duplicate

Comments

0

try to remove the first form tage :

**<form>**
<table border="0" align="center" cellpadding="0" cellspacing="1">
<form name="contact" method="post" action="sendmail.php">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.