Page 1 of 1

Page not forwarding

Posted: Sun Feb 21, 2010 8:00 am
by YourDirector
I have a contact form on my website and use the following to send it. I use the exact same form on another one of my websites and it works fine but on this one, although the email does send, it just ends with a blank screen and does not forward on to the correct page. Any idea's why?

Code: Select all

if (isset($HTTP_GET_VARS["sendmessage"])){
        $name = @$HTTP_POST_VARS["nam"];
        $eml = @$HTTP_POST_VARS["eml"];
        $msg = @$HTTP_POST_VARS["msg"];
        $regarding = @$HTTP_POST_VARS["regarding"];
        
        $to = "my@email.co.uk";
        $subject = "Josh Forwood - $regarding";
        $body = "From (Name): $name \nEmail: $eml \nRegarding: $regarding \nMessage: $msg \nIP Address: $add";
        $header = "From: $name <$eml>";
 
        mail($to, $subject, $body, $header);
 
        header("location:http://www.joshforwood.co.uk/?confirm");       
        exit(0);
    }

Re: Page not forwarding

Posted: Sun Feb 21, 2010 10:04 am
by F00Baron
I always capitalize Location and put a space after the colon in the header() function call. Not sure if either required.

Code: Select all

header("Location: http://www.joshforwood.co.uk/?confirm");
Also mail() function might be generating a fatal error. Check the apache error log.

Re: Page not forwarding

Posted: Sun Feb 21, 2010 2:09 pm
by flying_circus
Turn on error reporting and display errors to see what is happening. Headers must be sent before any other output, so be sure there are no blank lines in your file or other output, before sending this header.

Code: Select all

# Error Reporting
    error_reporting(E_ALL);
    ini_set("display_error", 1);

Re: Page not forwarding

Posted: Mon Feb 22, 2010 4:40 am
by wilded1
Also try adding your own error message:

Code: Select all

 
if (mail($to, $subject, $body, $header)){
          header("location:http://www.joshforwood.co.uk/?confirm");      
        exit(0);
}else{ echo" mail() failed to send";}
 
It could be that the header has already been sent and cannot be sent again, causing an error.

Try creating a php.ini file in the root folder containing:

Code: Select all

 
output_buffering = On