Web Hosting
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2012

    Default Form sends an email, displays a new page.

    Hey guys.

    I'm trying to write a PHP file that will take the data entered into a form on an html page and send it to an email address, with a nice, decent layout, and then display a new page once it is successful. Here's what I have so far, but for some reason it just isn't working.

    <form id="contact_form" method="post" action="send_form_email.php" novalidate>

    <input type="text" id="name" name="name" tabindex="1">

    <span id="sprytextfield1">
    <input type="text" name="validateEmail" id="validateEmail" tabindex="2"/>
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    <p class="center"><input type="submit" id="submit" value="Submit" tabindex="4">
    <a href="send_form_email.php">Email Form</a>
    <br />

    <div id="textarea">
    <span id="sprytextarea1">
    <textarea id="comments2" name="comments2" form="contact_form" tabindex="3"></textarea><br/>
    <span id="countsprytextarea1">* disabled word *</span><br/><span class="textareaRequiredMsg">A value is required.</span><span class="textareaMinChar* disabled word ** disabled word ** disabled word *g">Minimum number of characters not met.</span><span class="textareaMaxChar* disabled word ** disabled word ** disabled word *g">Exceeded maximum number of characters.</span></span></div><!-- #textarea -->
    </div><!--End forms-->
    And here's the PHP

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

    $email_to = "someRandomAddress@domain.com";
    $email_subject = "New Contact Form Submission";

    $name = $_POST['name']; // required
    $email_from = $_POST['validateEmail']; // required
    $comments = $_POST['comments2']; // required

    $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 .= "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 -->

    //essentially, this should redirect to a new page.


  2. #2
    Join Date
    May 2012
    Halifax - UK

    Red face Here is a tutorial on my website blog

  3. #3


    Very simple. First create the page to be redirected to:

    <p>Thanks for the message!</p>

    Named success.html.

    And then add this line in the PHP script immediately after it has sent the email:

    header('Location: /path/to/success.html');

    An easier approach is conditional detection such as this script.

Similar Threads

  1. how to set up form to send email
    By Run4it in forum Hosting Related Questions
    Replies: 1
    Last Post: 12-05-2008, 07:53 AM
  2. Replies: 3
    Last Post: 07-30-2006, 10:01 AM
  3. How to Email a form with Matt's FormMail script
    By alwaye in forum Hosting Related Questions
    Replies: 1
    Last Post: 04-28-2006, 08:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts