Pretty Easy PHP Problem (but I'm a newbie!)

Discussion in 'PHP' started by trwdesigns, May 27, 2008.

  1. #1
    Hi everyone,

    So I have a very simple contact form as follows:

    <?php
    if(isset($_POST["email"])){
    $headers = "From: ".$_POST
     
    trwdesigns, May 27, 2008 IP
  2. e96

    e96 Active Member

    Messages:
    299
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #2
    use
    header('Location: http://sitetogot . com /page/to/go/to.php');
    Code (markup):
    one caveat: you should call header prior to echoing or printing
     
    e96, May 27, 2008 IP
  3. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #3
    
    <?php
    if(isset($_POST["email"])){
    $headers = "From: ".$_POST[email]."\r\n";
    $headers .= "Content-type: text/html\r\n";
    $message = "
    <br />Name: $_POST[name] <br />E-mail: $_POST[email]<br /><br />$_POST[msg]
    ";
    mail("myemail@mydomain.com", "Website Form Submission", $message, $headers);
    // put your page here
    header("Location: http://site.com/thanx.html");
    }
    ?>
    
    PHP:
     
    AsHinE, May 27, 2008 IP
  4. Meth_

    Meth_ Well-Known Member

    Messages:
    1,063
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    140
    #4
    remember to put "exit;" after the header or else the rest of the script will still run
     
    Meth_, May 27, 2008 IP
  5. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yep, dont forget to use exit;

    Please use this code, it is more easy to modify :) :

    
    <?php
    if(isset($_POST["email"])){
    $thanks_page = 'Your Page URL here'; // Change it
    $title = 'Website Form Submission'; // Change it
    $email_owner = 'Your Email here'; // Change it
    
    $headers = "From: ".$_POST[email]."\r\n";
    $headers .= "Content-type: text/html\r\n";
    $message = "
    <br />Name: $_POST[name] <br />E-mail: $_POST[email]<br /><br />$_POST[msg]
    ";
    mail($email_owner, $title, $message, $headers);
    header("Location: $thanks_page");
    exit;
    }
    ?>
    
    PHP:
    Thank you
     
    nastynappy, May 27, 2008 IP
  6. trwdesigns

    trwdesigns Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you all for your help... it worked brilliantly!

    Muchas Gracias,
    Terrence
     
    trwdesigns, May 27, 2008 IP
  7. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #7
    er.. I expected a +rep after helping you :)
    but nvm if you didnt,... Glad my coding worked :)
     
    nastynappy, May 28, 2008 IP
    Meth_ and exploreankit like this.