Contact form problems

Discussion in 'PHP' started by bozo83, Mar 19, 2010.

  1. #1
    Hey everyone, I'm a bit of a newbie to php scripting, and have unfortunatly hit my first bump on my first php page!! I've basically placed a php contact form on my page supplied by somebody else, and altho it kinda works (it sends me mail!) they person sending the message doesn't get redirected to my "thank you page like they should, instead the following two errors are displayed:


    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /customers/landmark-joinery.co.uk/landmark-joinery.co.uk/httpd.www/contact.php:44) in /customers/landmark-joinery.co.uk/landmark-joinery.co.uk/httpd.www/securimage.php on line 1

    Warning: Cannot modify header information - headers already sent by (output started at /customers/landmark-joinery.co.uk/landmark-joinery.co.uk/httpd.www/contact.php:44) in /customers/landmark-joinery.co.uk/landmark-joinery.co.uk/httpd.www/contact.php on line 239

    Any idea why this is happening? and how I can correct the problem?? I can supply the html/php code if you require.

    Thanks in advance for any help given! Bozo
     
    bozo83, Mar 19, 2010 IP
  2. SecureCP

    SecureCP Guest

    Messages:
    226
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    sounds dumb, but make sure there's no whitespace around your php tags.
     
    SecureCP, Mar 19, 2010 IP
    bozo83 likes this.
  3. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #3
    could be whitespace like SecureCP said. but the problem is your script is trying to modify the HTTP headers after the page is being displayed. So what you have to do is be sure there's no HTML (including spaces) sent to the browser before the redirect.
     
    shallowink, Mar 19, 2010 IP
    bozo83 likes this.
  4. bozo83

    bozo83 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So I'd read about the whitespace before php code before and made sure that I didn't have any, but didn't know you couldn't have html code before the php, so I made a page header and page footer php page and placed the html coding in them then set links up in the php script...works a treat. Thank you very much guys!
     
    bozo83, Mar 19, 2010 IP
  5. Latox

    Latox Active Member

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    96
    #5
    Do you have BOM?
     
    Latox, Mar 20, 2010 IP
  6. bozo83

    bozo83 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Whats BOM?? Am I being thick for not knowing what that is?
     
    bozo83, Mar 20, 2010 IP
  7. Brad Proctor

    Brad Proctor Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    
    <?php
    
    // Check to see if the form was submitted by checking one of the post variables
    if(isset($_POST['first_name'])) {
       // check your input, don't want your form to be used for spam!
       ...
    
       // send your message
       mail(...);
    
       // redirect to confirmation page
       header('Location: /thanks.php');
    }
    ?>
    <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
       ...
    </form>
    
    Code (markup):
    Here's the basic layout for a contact form page
     
    Brad Proctor, Mar 20, 2010 IP
  8. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #8
    only BOM I'm aware of is UTF W/ BOM and its a file type. If a text file is saved as UTF w/BOM it can result in php pages not working properly though IIRC the error is different. BOM stands for Byte Order Mark. doubt that's your issue.
     
    shallowink, Mar 20, 2010 IP
  9. Brad Proctor

    Brad Proctor Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Never heard of BOM either.
     
    Brad Proctor, Mar 20, 2010 IP
  10. mattinblack

    mattinblack Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Tick....Tock.... Tick....Tock.... Tick....Tock.... Tick....Tock.... Tick....Tock....BOOOM!!
    Actually you can redirect from PHP after you sent headers - but its kinda sneaky I use it a lot on PHP Logout forms - Just do a google search on 'ultimate page redirection techniques webmaster-a' and you will get it - its on a whole useful page about redirect techniques!
     
    mattinblack, Mar 20, 2010 IP
  11. bozo83

    bozo83 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thanks everyone and I hope this post helps more people out. It all seems to be working fine now!!
     
    bozo83, Mar 23, 2010 IP