www.webdeveloper.com
Results 1 to 4 of 4

Thread: contact form - cannot modify header

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Posts
    6

    contact form - cannot modify header

    Hi,

    I've build a contact form and it works, but I can't get the thankyou message to appear. I keep getting the following error message which I don't understand as I can see anything wrong with line 46. Any suggestions...I'm new!

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/24/10758824/html/contact.php:2) in /home/content/24/10758824/html/contact.php on line 46


    PHP Code:

    <?php 

    if ($_SERVER["REQUEST_METHOD"] =="POST") {
        
    $name $_POST ["name"];
        
    $email $_POST ["email"];
        
    $message $_POST ["message"];
        
        foreach( 
    $_POST as $value ){
            if( 
    stripos($value'Content-Type:') !== FALSE){
                echo 
    "There was a problem with the information you entered.";
                exit;
            }
        }
        
        if (
    $_POST["twitter"] != "") {
            echo 
    "Your form has an error";
            exit;
        }
        
        require_once(
    "inc/phpmailer/class.phpmailer.php");
        
    $mail = new PHPMailer();
        
        
        
    $email_body "";
        
    $email_body $email_body "Name: " $name ."<br>";
        
    $email_body $email_body "Email: " $email "<br>";
        
    $email_body $email_body "Message: " $message;
        
        
        
    $mail->SetFrom($email$name);
            
        
    $address "my@email.com";
        
    $mail->AddAddress($address"myaddress");
        
        
    $mail->Subject    "contact |" $name;
            
        
    $mail->MsgHTML($email_body);
        

    if(!
    $mail->Send()) {
      echo 
    "Mailer Error: " $mail->ErrorInfo;
      exit;

        
    [
    B] (LINE 46) [/B]  header('Location:contact-thanks.php?status=thanks');
        exit;
        }
        
    ?>
    Thanks,
    Matt

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,935
    This is the "important" part of that error message:
    output started at /home/content/24/10758824/html/contact.php:2
    ...which states that something was output at line 2.

    At least in what you pasted here, it looks like you have, at a minimum, a newline before the opening <?php tag, which means that you are, at a minimum, outputting a newline to the browser at that point, thus you can no longer change/set HTTP headers, since they must be sent before any output is.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2013
    Posts
    6
    That's what it was, blank line on line one. Thanks!

    (I feel stooooopid!)

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,935
    There ain't a PHP programmer out there who hasn't done that (unless s/he's never done any real PHP programming).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles