SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    charleston
    Posts
    351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thank you page - after contact form

    Hi all,

    I have a contact.html page that includes a form to fill out. when the user hits submit, the mail.php comes into play. However, I would like to go to a thankyou.html page instead of the mail.php. Whats the line of code in php to push somebody to a different page?

    here is what form and mail.php looks like now.
    (how do I properly enter code in the forum post??)

    contact.html:
    ____________________________________________________________

    <form id="two" method="POST" action="mailer.php">
    <fieldset id="personal">
    <legend>Contact Information </legend>

    <label for="lastname">name : </label>
    <input name="name" id="lastname" type="text"
    tabindex="1" /><br />

    <label for="address">email : </label>
    <input name="email" id="address" type="text"
    tabindex="3" /><br />
    </fieldset>
    <br />
    <fieldset id="current">
    <legend>Your Message </legend>
    <p>
    <textarea name="message" cols="40" rows="10">
    </textarea>
    </p>
    </fieldset>
    <p>
    <input id="button1" type="submit" value="Submit" name='submit' />
    <input id="button2" type="reset" />
    </p>
    </form>
    ____________________________________________________________

    mail.php

    <?php
    if(isset($_POST['submit'])) {

    $to = "info@xz.com";
    $subject = "Contact Form";
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $message = $_POST['message'];

    $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

    echo "Data has been submitted to $to!";
    mail($to, $subject, $body);

    } else {

    echo "Please go back and fill out all fields.";

    }
    ?>
    _______________________________________________________________

    thank you,
    Florian

  2. #2
    SitePoint Guru
    Join Date
    Dec 1999
    Location
    Southampton, Hants, UK
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    header("Location: mypage.php");

    you need to send that before any data is sent to the browser - for instance before any echo statements or HTML is printed in mail.php

  3. #3
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    header("Location: thankyou.php");
    Put this right below your mail() function.
    Edit:


    ... and daniel above is right about not sending any output to the browser before the header() call.

  4. #4
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you make your thankyou page the same page as mail.php. Just put all your html for the thankyou page under the php code. Like so...

    PHP Code:
    <?php
    if(isset($_POST['submit'])) {

    $to "info@poulsbocityhall.com";
    $subject "Poulsbocityhall Contact Form";
    $name_field $_POST['name'];
    $email_field $_POST['email'];
    $message $_POST['message'];

    $body "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

    echo 
    "Data has been submitted to $to!";
    mail($to$subject$body);

    } else {

    echo 
    "Please go back and fill out all fields.";

    }
    ?>

    <html>
    <body>
    Thankyou for your email!
    </body>
    </html>
    or, you can use the file_get_contents function to include your thankyou.html page in the script...

    PHP Code:
    <?php
    if(isset($_POST['submit'])) {

    $to "info@poulsbocityhall.com";
    $subject "Poulsbocityhall Contact Form";
    $name_field $_POST['name'];
    $email_field $_POST['email'];
    $message $_POST['message'];

    $body "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

    echo 
    "Data has been submitted to $to!";
    mail($to$subject$body);

    $thankyou file_get_contents("thankyou.html");

    echo 
    $thankyou;


    } else {

    echo 
    "Please go back and fill out all fields.";

    }
    ?>
    That will print the contents of your thankyou.html to the browser and will appear exactly the same as if you viewed thankyou.html directly.

  5. #5
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or, you can include it all in the one page...
    Code:
    <form id="two" method="POST" action="<?php $_SERVER['PHP_SELF'] ?>">
    <fieldset id="personal">
    <legend>Contact Information </legend>
    
    <label for="lastname">name : </label>
    <input name="name" id="lastname" type="text"
    tabindex="1" /><br />
    
    <label for="address">email : </label>
    <input name="email" id="address" type="text"
    tabindex="3" /><br />
    </fieldset>
    <br />
    <fieldset id="current">
    <legend>Your Message </legend>
    <p>
    <textarea name="message" cols="40" rows="10">
    </textarea>
    </p>
    </fieldset>
    <p>
    <input id="button1" type="submit" value="Submit" name='submit' />
    <input id="button2" type="reset" />
    </p>
    </form>
    
    <?php
    if(isset($_POST['submit'])) {
    
    $to = "info@xz.com";
    $subject = "Contact Form";
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $message = $_POST['message'];
    
    $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
    
    echo "Data has been submitted to $to!";
    mail($to, $subject, $body);
    
    $thankyou = file_get_contents("thankyou.html");
    
    echo $thankyou; 
    }
    ?>

  6. #6
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    charleston
    Posts
    351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AWESOME! I just made the mail.php my thank you page. that works really great, and I dont even have to forward to another page.

    guys, thank you very much!
    Florian

  7. #7
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem

  8. #8
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hugs all round

  9. #9
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    charleston
    Posts
    351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    may i raise another question:

    when I receive the email in outlook that was sumitted through the form online, the from name says "Nobody.."
    Isnt there a way to have the value from the email field appear in the "from" section in the email that i receive??
    make sense?

    florian


Bookmarks

Posting Permissions

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