Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Regular Coder
    Join Date
    Oct 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    contact form error

    I have a simple php form I've been using for client's contact pages for years. It's worked great, but something is wrong with it now. I get an error:
    Warning: Cannot modify header information - headers already sent by (output started at /home/content/a/l/p/alpineec/html/TEST/contact.php:9) in /home/content/a/l/p/alpineec/html/TEST/contact.php on line 47

    LINE 47: header ('Location: http://www.alpineec.com/TEST/thank-you_02.php');

    http://alpineec.com/TEST/contact.php


    Any thoughts on how to fix it?


    In the <head> tags:
    PHP Code:
    <head>


      <meta http-equiv="zrefresh" content="3">
      <meta http-equiv="content-type" content="text/html; charset=utf-8"><title>Alpine Environmental Consulting</title>
    <link rel="stylesheet" type="text/css" href="default.css" />

    <?php
    if(isset($_POST['submit'])) { // Following code is to Handle the HTML Forum
        
        
    $message NULL// Variable to hold final error message if something is not filled out.
        
        // Check if the name was entered.
        
    if(strlen($_POST['name']) > 0) { // if statement checks the length of the name to be greater than 0
             
    $name TRUE;
        } else {
             
    $name FALSE;
             
    $message .= '<P>You forgot to enter your name!</p>';
        }
        
    // Check if the Return e-mail address was entered.
        
    if(strlen($_POST['email']) > 0) { // if statment to check just like we did the name value
             
    $email TRUE;
        } else {
             
    $email FALSE;
             
    $message .= '<p>You forgot to enter your e-mail address!</p>';
        }
        
    // Check if the Subject is intact. 
        
    if(strlen($_POST['subject']) > 0) { // if statment to check just like we did the others
             
    $subject TRUE;
        } else {
             
    $subject FALSE;
             
    $message .= '<p>You forgot to enter a subject!</p>';
        }
        
    // Check if anything was entered into the body.
        
    if(strlen($_POST['body']) > 0) { // if statment to check just like before
             
    $body TRUE;
        } else {
             
    $body FALSE;
             
    $message .= '<p>You forgot to enter your e-mail address!</p>';
        }
        if(
    $name && $email && $subject && $body) { // if everything was entered...
             // Send the email
             
    $headers "From: {$_POST['name']}\r\n"// Create a From part of the email
             
    $headers .= "Reply-To: {$_POST['email']}\r\n"// Create the Reply-To so you can reply w/their email
             
    mail ('jmulqueen@gmail.com'$_POST['subject'], $_POST['body'], $headers); // This will send the email
             
    header ('Location: http://www.alpineec.com/TEST/thank-you_02.php'); // will redirect them to a thank-you page
             
    exit();
        } else {
             
    $message .= '<p>Please try again.</p>';
        }
    }
    ?>

    </head>
    Actual form:
    PHP Code:
      <?php
    if (isset($message)) { // if there is an error, print them
        
    echo '<font color="red">'$message,'</font>';
    }
    ?>
    </p> Questions or Comments?  Send us an e-mail with the form below!<br />
    <br />
    <form method="POST" action="<?=$PHP_SELF?>">
      <p>Name: 
        <input type="text" name="name" size="20">
      <p> Email:&nbsp; 
        <input type="text" name="email" size="20">
      <p>Subject<font size="2"></font>: 
        <input type="text" name="subject" size="70">
        <br>
        <font size="2"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em></font> <br>
        Comments or Questions:<br>
        <br>
        <textarea rows="8" name="body" cols="80"></textarea>
        <br>
        <input type="submit" name="submit" value="Send">
        <input type="reset" value="Reset">
        <br>
    </form>

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    move this part:
    Code:
    <head>
    
    
      <meta http-equiv="zrefresh" content="3">
      <meta http-equiv="content-type" content="text/html; charset=utf-8"><title>Alpine Environmental Consulting</title>
    <link rel="stylesheet" type="text/css" href="default.css" />
    after the '?>' and before this:
    Code:
    </p> Questions or Comments?  Send us an e-mail with the form below!<br />
    <br />
    <form method="POST" action="<?=$PHP_SELF?>">
    Edit: sorry, wrong message. correct is "move the part I said after '?>' and before '</head>'"

    regards
    Last edited by oesxyl; 07-21-2008 at 12:36 AM.

  • #3
    Regular Coder
    Join Date
    Oct 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Same error. Line 42 now...which is the same code

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

    <?php
    if(isset($_POST['submit'])) { // Following code is to Handle the HTML Forum
        
        
    $message NULL// Variable to hold final error message if something is not filled out.
        
        // Check if the name was entered.
        
    if(strlen($_POST['name']) > 0) { // if statement checks the length of the name to be greater than 0
             
    $name TRUE;
        } else {
             
    $name FALSE;
             
    $message .= '<P>You forgot to enter your name!</p>';
        }
        
    // Check if the Return e-mail address was entered.
        
    if(strlen($_POST['email']) > 0) { // if statment to check just like we did the name value
             
    $email TRUE;
        } else {
             
    $email FALSE;
             
    $message .= '<p>You forgot to enter your e-mail address!</p>';
        }
        
    // Check if the Subject is intact. 
        
    if(strlen($_POST['subject']) > 0) { // if statment to check just like we did the others
             
    $subject TRUE;
        } else {
             
    $subject FALSE;
             
    $message .= '<p>You forgot to enter a subject!</p>';
        }
        
    // Check if anything was entered into the body.
        
    if(strlen($_POST['body']) > 0) { // if statment to check just like before
             
    $body TRUE;
        } else {
             
    $body FALSE;
             
    $message .= '<p>You forgot to enter your e-mail address!</p>';
        }
        if(
    $name && $email && $subject && $body) { // if everything was entered...
             // Send the email
             
    $headers "From: {$_POST['name']}\r\n"// Create a From part of the email
             
    $headers .= "Reply-To: {$_POST['email']}\r\n"// Create the Reply-To so you can reply w/their email
             
    mail ('jmulqueen@gmail.com'$_POST['subject'], $_POST['body'], $headers); // This will send the email
             
    header ('Location: http://www.alpineec.com/TEST/thank-you_02.php'); // will redirect them to a thank-you page
             
    exit();
        } else {
             
    $message .= '<p>Please try again.</p>';
        }
    }
    ?>
    <head>
      <meta http-equiv="zrefresh" content="3">
      <meta http-equiv="content-type" content="text/html; charset=utf-8"><title>Alpine Environmental Consulting</title>
    <link rel="stylesheet" type="text/css" href="default.css" />
    </head>

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    because is the same mistake:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    you can't put html code or print/echo anything before the line with the header.

    regards

  • #5
    Regular Coder
    Join Date
    Oct 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    good to know...but same error!

    PHP Code:
    <?php
    if(isset($_POST['submit'])) { // Following code is to Handle the HTML Forum
        
        
    $message NULL// Variable to hold final error message if something is not filled out.
        
        // Check if the name was entered.
        
    if(strlen($_POST['name']) > 0) { // if statement checks the length of the name to be greater than 0
             
    $name TRUE;
        } else {
             
    $name FALSE;
             
    $message .= '<P>You forgot to enter your name!</p>';
        }
        
    // Check if the Return e-mail address was entered.
        
    if(strlen($_POST['email']) > 0) { // if statment to check just like we did the name value
             
    $email TRUE;
        } else {
             
    $email FALSE;
             
    $message .= '<p>You forgot to enter your e-mail address!</p>';
        }
        
    // Check if the Subject is intact. 
        
    if(strlen($_POST['subject']) > 0) { // if statment to check just like we did the others
             
    $subject TRUE;
        } else {
             
    $subject FALSE;
             
    $message .= '<p>You forgot to enter a subject!</p>';
        }
        
    // Check if anything was entered into the body.
        
    if(strlen($_POST['body']) > 0) { // if statment to check just like before
             
    $body TRUE;
        } else {
             
    $body FALSE;
             
    $message .= '<p>You forgot to enter your e-mail address!</p>';
        }
        if(
    $name && $email && $subject && $body) { // if everything was entered...
             // Send the email
             
    $headers "From: {$_POST['name']}\r\n"// Create a From part of the email
             
    $headers .= "Reply-To: {$_POST['email']}\r\n"// Create the Reply-To so you can reply w/their email
             
    mail ('jmulqueen@gmail.com'$_POST['subject'], $_POST['body'], $headers); // This will send the email
             
    header ('Location: http://www.alpineec.com/TEST/thank-you_02.php'); // will redirect them to a thank-you page
             
    exit();
        } else {
             
    $message .= '<p>Please try again.</p>';
        }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

    <head>

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tns123j View Post
    good to know...but same error!
    I'm glad,

    this apply also to the files where this file is included, I mean before the line 'include(....)' you can't put html code or print/echo anything.

    regards

  • #7
    Regular Coder
    Join Date
    Oct 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The error is still there. Any thoughts?

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tns123j View Post
    The error is still there. Any thoughts?
    did you check files where is included?

    regards

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    That should be working. I suggest you remove your email address from your posts as well. Just went to your site and it appears to be working just fine.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    Regular Coder
    Join Date
    Oct 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    everything is included. Try the form yourself. You'll see the error.

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/a/l/p/alpineec/html/TEST/contact.php:2) in /home/content/a/l/p/alpineec/html/TEST/contact.php on line 40

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tns123j View Post
    everything is included. Try the form yourself. You'll see the error.

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/a/l/p/alpineec/html/TEST/contact.php:2) in /home/content/a/l/p/alpineec/html/TEST/contact.php on line 40
    this file is ok, post the file where is the form.

    regards

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Please post all of your code for contact.php

    header calls MUST be before HTML output. There are ways to get around it but then thats just being lazy.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    Regular Coder
    Join Date
    Oct 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    if(isset($_POST['submit'])) { // Following code is to Handle the HTML Forum
        
        
    $message NULL// Variable to hold final error message if something is not filled out.
        
        // Check if the name was entered.
        
    if(strlen($_POST['name']) > 0) { // if statement checks the length of the name to be greater than 0
             
    $name TRUE;
        } else {
             
    $name FALSE;
             
    $message .= '<P>You forgot to enter your name!</p>';
        }
        
    // Check if the Return e-mail address was entered.
        
    if(strlen($_POST['email']) > 0) { // if statment to check just like we did the name value
             
    $email TRUE;
        } else {
             
    $email FALSE;
             
    $message .= '<p>You forgot to enter your e-mail address!</p>';
        }
        
    // Check if the Subject is intact. 
        
    if(strlen($_POST['subject']) > 0) { // if statment to check just like we did the others
             
    $subject TRUE;
        } else {
             
    $subject FALSE;
             
    $message .= '<p>You forgot to enter a subject!</p>';
        }
        
    // Check if anything was entered into the body.
        
    if(strlen($_POST['body']) > 0) { // if statment to check just like before
             
    $body TRUE;
        } else {
             
    $body FALSE;
             
    $message .= '<p>You forgot to enter your e-mail address!</p>';
        }
        if(
    $name && $email && $subject && $body) { // if everything was entered...
             // Send the email
             
    $headers "From: {$_POST['name']}\r\n"// Create a From part of the email
             
    $headers .= "Reply-To: {$_POST['email']}\r\n"// Create the Reply-To so you can reply w/their email
             
    mail ('jmulqueen@gmail.com'$_POST['subject'], $_POST['body'], $headers); // This will send the email
             
    header ('Location: http://www.alpineec.com/TEST/thank-you_02.php'); // will redirect them to a thank-you page
             
    exit();
        } else {
             
    $message .= '<p>Please try again.</p>';
        }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

    <head>
      <meta http-equiv="zrefresh" content="3">
      <meta http-equiv="content-type" content="text/html; charset=utf-8"><title>Alpine Environmental Consulting</title>
    <link rel="stylesheet" type="text/css" href="default.css" />
    </head>
    <body>

    <div id="upbg"></div>

     <div id="outer">


    <div id="header">
            <div id="headercontent">
              <h2>&nbsp;</h2>
        </div>
      <img src="images/main_logo_noglow" alt="Alpine" width="700" height="150" />  </div>

        <div id="menu">
            <!-- HINT: Set the class of any menu link below to "active" to make it appear active -->
            <ul>
              <li><a href="index.php">Home</a></li>
              <li><a href="aboutus.php">About Us</a></li>
              <li><a href="services.php">Services</a></li>
              <li><a href="projects.php">Projects</a></li>
              <li><a href="testimonials.php">Testimonials</a></li>
              <li><a href="contact.php" class="active">Contact</a></li>
          </ul>
      </div>

        <div id="content"><div id="normalcontent">
    <div class="contentarea">
                    <!-- Normal content area start -->
                    <p id="style">
                    Alpine Environmental Consultants<br>
                    Suite G<br />
                    201 Ward St.<br />
                    Montgomery, NY 12549<br />
                    <br />
                    Phone: (845) 457-8141<br />
                    Fax:(845) 457-8763
        <br />
        <br /><iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=201+Ward+St.+Montgomery,+NY+12549&amp;sll=37.0625,-95.677068&amp;sspn=35.957999,84.199219&amp;ie=UTF8&amp;s=AARTsJq27qQ0kqbq6wHZDj4NpLDXbruzAg&amp;ll=41.534218,-74.226294&amp;spn=0.019275,0.025749&amp;z=14&amp;iwloc=addr&amp;output=embed"></iframe>
        <br />
        </p>
      <?php
    if (isset($message)) { // if there is an error, print them
        
    echo '<font color="red">'$message,'</font>';
    }
    ?>
    </p> Questions or Comments?  Send us an e-mail with the form below!<br />
    <br />
    <form method="POST" action="<?=$PHP_SELF?>">
      <p>Name: 
        <input type="text" name="name" size="20">
      <p> Email:&nbsp; 
        <input type="text" name="email" size="20">
      <p>Subject<font size="2"></font>: 
        <input type="text" name="subject" size="70">
        <br>
        <font size="2"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em></font> <br>
        Comments or Questions:<br>
        <br>
        <textarea rows="8" name="body" cols="80"></textarea>
        <br>
        <input type="submit" name="submit" value="Send">
        <input type="reset" value="Reset">
        <br>
    </form>
            <!-- Primary content: Stuff that goes in the primary content column (by default, the left column) -->
          </div>
          </div>

        
      <div id="primarycontainer">    </div>

            
            <!-- Secondary content: Stuff that goes in the secondary content column (by default, the narrower right column) -->
      </div>

      <div id="footer">
            <div class="left">
                  <?php include('./footer.php');?>
    </div>
      </div>
    </div>

    </body>

    </html>

  • #14
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    replace this:
    PHP Code:
    <?php
    if (isset($message)) { // if there is an error, print them
        
    echo '<font color="red">'$message,'</font>';
    }
    ?>
    with this:
    PHP Code:
    <?php
      
    <?php
    if (isset($message) && !isset($_POST['submit'])) { // if there is an error, print them
        
    echo '<font color="red">'$message,'</font>';
    }
    ?>
    regards

  • #15
    Regular Coder
    Join Date
    Oct 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    perfect. thanks!


  •  

    Posting Permissions

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