Skip navigation
crispybean
Currently Being Moderated

Contact Form not sending email

Feb 20, 2013 7:53 PM

Hi there,

 

After battling this problem for hours I have bitten the bullet and am asking for HELP!

 

My contact form is not working, it was working, then wasn't...then was and now its definately not! The thankyou page is appearing when I have filled in the details and click SUBMIT- I am just not receiving the email.

 

Here is my form HTML coding (I have highlighted the code that I think is making the form work and not work- as explained below!);

 

<section id ="outersection">

<article>

 

<form name="contactform" method="post" action="thankyou.html">

<table width="450px">

</tr>

<tr>

<td valign="top">

  <label for="first_name">First Name *</label>

</td>

<td valign="top">

  <input  type="text" name="first_name" maxlength="50" size="30">

</td>

</tr>

 

 

<tr>

<td valign="top">

  <label for="last_name">Last Name *</label>

</td>

<td valign="top">

  <input  type="text" name="last_name" maxlength="50" size="30">

</td>

</tr>

<tr>

<td valign="top">

  <label for="email">Email Address *</label>

</td>

<td valign="top">

  <input  type="text" name="email" maxlength="80" size="30">

</td>

 

 

</tr>

<tr>

<td valign="top">

  <label for="telephone">Telephone Number</label>

</td>

<td valign="top">

  <input  type="text" name="telephone" maxlength="30" size="30">

</td>

</tr>

<tr>

<td valign="top">

  <label for="comments">Products Requested*</label>

</td>

<td valign="top">

  <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>

</td>

 

 

</tr>

<tr>

<td colspan="2" style="text-align:center">

 

 

  <input type="submit" value="Submit"></td>

</tr>

</table>

</form>

 

 

 

</article>

</section>

<!-- start small section-->

<article id= "information">

  <h1> Thankyou for visiting us at</h1>

</article>

<!--end small section-->

<!-- start footer-->

<footer>

  <p>Final Website </p>

  <p></p>

</footer>

<!--end footer-->

</body>

</html>

 

 

 

 

 

 

AND my php coding;

 

 

 

 


 

<?php

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

    

    // EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to = "sales@xxxxxxxxxxx.com.au";

    $email_subject = "Order Received";

    

    

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

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

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

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

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

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

    }

    

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

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

    $email_from = $_POST['email']; // required

    $telephone = $_POST['telephone']; // not required

    $comments = $_POST['comments']; // 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,$first_name)) {

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

  }

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

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

  }

  if(strlen($comments) < 2) {

    $error_message .= 'The Comments 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 .= "First Name: ".clean_string($first_name)."\n";

    $email_message .= "Last Name: ".clean_string($last_name)."\n";

    $email_message .= "Email: ".clean_string($email_from)."\n";

    $email_message .= "Telephone: ".clean_string($telephone)."\n";

    $email_message .= "Comments: ".clean_string($comments)."\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 -->

<title>contactform</title>

<h1>Thank you for your order - one of our friendly sales team will confirm your order soon</h1>

 

 

 

 

 

Now, the problem (I think) lies in the highlighted row of HTML code. When I changed it to this <form name="contactform" method="post" action="html_form_send.php">

 

the EMAIL worked, but the thankyou page did not appear- just basic text on a blank screen that when clicked 'back' from you are sent back to the form or if closed, closed the whole browser. When changed back to the orginal the thankyou page appeared but no email...

 

Is there a simple answer to get BOTH actions working?! I would be forever thankful for anyone's assistance, this is my first live site and my client has been very patient so far...but time is ticking! 

 

Thanks

 
Replies
  • Currently Being Moderated
    Feb 20, 2013 9:56 PM   in reply to crispybean

    The action attribute of the form tag tells the brower what page to send the form to - so you need to set it to the PHP page that has the processing script -- html_form_send.php - and not the thank you page. Your php script needs to contain the code that will redirect the user to the thank you page after it has processed the form fields.

     


     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2013 11:05 PM   in reply to crispybean

    If you have PHP available, then you should rename 'thankyou.html' to 'thankyou.php'

     

    The contents of 'thankyou.php' will look similar to, where the highlighted part needs to be customised

    <?php

    if(isset($_POST["Submit"])){

          $to="me@mydomain.com";

          $from=$_POST["Email"];

          //Make sure the email address has been entered

          if($from == ""){

                echo "Please specify your email address";

                die();

          }

          //At first the message is blank

          $message="";

          //Loop through all the field and put together the message

     

          foreach($_POST as $fieldName => $value){

                if($fieldName!="Submit"){

                      $fieldValue=$value;

                      $message= $message."<b>$fieldName</b>: $fieldValue<br>";

                }

          }

     

          $html_header.= "\r\nContent-type: text/html; charset=iso-8859-1;";

          $headers="From:".$from.$html_header;

          $subject="Message sent from web site";

          if(mail($to, stripslashes($subject), stripslashes($message),$headers)){

                echo "The message has been sent";

                die();

          }else{

                echo "Error sending message";

               die();

          }

    }?>

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 21, 2013 2:58 AM   in reply to crispybean
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 21, 2013 11:46 AM   in reply to Ben Pleysier

    @Gramps, I think you did not read the OP's entire post. It looks like it was working when submitting to a php page but they changed the form action to go to a thank you html page so of course it no longer will work.

     

     

    @crispybean, I don't know php very well but you simply need to redirect the page after email processing is complete. So add the last line here:

     

    // 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); 

     

    header('Location: http://www.example.com/thankyou.htm');

    ?>

    http://www.xyz.co.in/%27%29;

     
    |
    Mark as:
  • Jim Carpenter
    546 posts
    Apr 6, 2006
    Currently Being Moderated
    Feb 21, 2013 12:06 PM   in reply to bregent

    I think what the poster is wanting is the same that is covered here:

     

    http://forums.adobe.com/message/5091483#5091483

     

    Jim

     

    Updated: change your form action back to: <form name="contactform" method="post" action="html_form_send.php">

     

    Then create a "thank you" webpage that you can redirect it to. Then follow the instructions in the link above to redirect once the form is submitted.

     

     

     

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 21, 2013 4:00 PM   in reply to bregent

    @bregent,

     

    Another senior moment! 

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 21, 2013 4:02 PM   in reply to crispybean

    Are you using GoDaddy?

     

    Nancy O.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points