A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: HTML, PHP Contact form

  1. #1
    I'm still learning...
    Join Date
    Nov 2004
    Location
    Malaysia
    Posts
    284

    Unhappy HTML, PHP Contact form

    I've followed some tutorials from the internet about making a HTML and PHP contact form, all went well (i can receive emails using the form) except when i try to redirect it to a new HTML page after submitting the email, it shows an error.

    Warning: Cannot modify header information - headers already sent by (output started at /home/jasonro/public_html/speakartdesign/clients/plaxeld/contact.php:2) in /home/jasonro/public_html/speakartdesign/clients/plaxeld/contact.php on line 17

    PHP Code:
    <?
    $subject="from ".$_POST['your_name'];
    $headers= "From: ".$_POST['your_email']."\n";
     $headers.='Content-type: text/html; charset=iso-8859-1';
    mail("me@jasonpang.com", $subject,  "
    <html>
    <head>
     <title>Contact letter</title>
    </head>
    <body>

    <br>
      ".$_POST['message']."
    </body>
    </html>" , $headers);
    header('Location: sent.html');
    ?>
    If i don't put that last line, header('Location: sent.html');, it'll go to a blank page, but that's not what i want. I want it to be redirected to a page where it says that their email has been sent, but it doesn't work if i put that header('Location: index.html');.

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    To use a header() call, no other output can be present before that call is made. Not even white space. So to me, it seems that there is probably a line break ABOVE your starting PHP tag, or a space, or something of that sort. Unless you're not posting the whole script and have some kind of echo statements somewhere.

    Check around for that, if you're still having an issue, post up your entire php file.

  3. #3
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Actually, upon some closer inspection, it seems that you have a linebreak before your starting PHP tag. I say this because your error is pointing to line 17 of the file.

    In the code you posted, the header() call is on line 16. So there has to be an empty line above that you didn't paste here.

  4. #4
    I'm still learning...
    Join Date
    Nov 2004
    Location
    Malaysia
    Posts
    284
    Someone from my hosting support offered me a solution. Instead of redirecting, I can put my html code down there.

    PHP Code:
    <?php 

    $message 
    '';
    $success false;

    foreach(
    $_POST as $t => $v)
        
    $message .= $t.': '.$v."\n\n";

    if( 
    strlen($message) > 2) {
        
    $message "Someone recently used the form submission. Here are the details:\n\n".$message;
        
    $success =  mail "me@jasonpang.com" "Form Sumission" $message );
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    </head>
    <body>
    </body>
    </html>

  5. #5
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Yeah, there is that. But I was trying more to fix your error.

  6. #6
    I'm still learning...
    Join Date
    Nov 2004
    Location
    Malaysia
    Posts
    284
    Thanks taco

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center