Page not forwarding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
YourDirector
Forum Newbie
Posts: 2
Joined: Wed Feb 03, 2010 9:17 pm

Page not forwarding

Post 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);
    }
User avatar
F00Baron
Forum Newbie
Posts: 6
Joined: Sat Feb 20, 2010 11:43 am

Re: Page not forwarding

Post 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.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Page not forwarding

Post 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);
wilded1
Forum Newbie
Posts: 9
Joined: Sun Feb 21, 2010 11:49 am

Re: Page not forwarding

Post 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
 
Post Reply