judkels Posted September 11, 2010 Report Share Posted September 11, 2010 I am very much a beginner with php and must be making a simple mistake. On one web host this seems to work ok for my contact form but not with another. I am getting the message warning cannot modify headers ...already sent... and so on. Can anyone point out where I am going wrong. I want the viewer to be redirected to my thank you page. This is my process.php - the actual message arrives ok but they are not redirected to the thank you page. <?php $email_to = "webmaster@xxxxxx"; $name = $_POST["name"]; $email_from = $_POST["email"]; $message = $_POST["message"]; $email_subject = "Feedback from website"; $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; $message = "Name: ". $name . "\r\nMessage: " . $message; ini_set("sendmail_from", $email_from); $sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from); if ($sent) { header("Location: http://www.xxxxxxxxxx/thankyou.html"); } else { echo "There has been an error sending your comments. Please try later."; } ?> I've already tried a few solutions but not any that have worked! Many thanks Judy Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 11, 2010 Report Share Posted September 11, 2010 A "header already sent" error usually means that something has been displayed in the browser before you try to use header(). The first thing I would check is if there is any blank lines or empty space at the start of the file, before the opening "<?php". Make sure that the "<" is the first character in the file. Quote Link to comment Share on other sites More sharing options...
judkels Posted September 12, 2010 Author Report Share Posted September 12, 2010 A "header already sent" error usually means that something has been displayed in the browser before you try to use header(). The first thing I would check is if there is any blank lines or empty space at the start of the file, before the opening "<?php". Make sure that the "<" is the first character in the file. I have checked that and know there must be something else since the same file works ok with a test site - goes straight to the thankyou page. Any other ideas I can try? Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 12, 2010 Report Share Posted September 12, 2010 I didn't catch this earlier, but these lines are incorrect: $headers ="From: $email_from .\n"; "Reply-To: $email_from .\n"; it should be $headers = " From: $email_from \n Reply-To: $email_from \n"; I'd correct this, do a bit more testing, and then report back. It may have nothing to do with the error, but it does seem to be a mistake in the code. Quote Link to comment Share on other sites More sharing options...
judkels Posted September 12, 2010 Author Report Share Posted September 12, 2010 I didn't catch this earlier, but these lines are incorrect: it should be $headers = " From: $email_from \n Reply-To: $email_from \n"; I'd correct this, do a bit more testing, and then report back. It may have nothing to do with the error, but it does seem to be a mistake in the code. I've changed as you suggested and it has sorted out the email sent to look better but I'm still getting no thankyou page and the warning about the header as before. many thanks Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 12, 2010 Report Share Posted September 12, 2010 Would you mind posting the full error that you are getting? Usually the error message tells you line numbers, showing where something was output to the browser. I'm not seeing anything else wrong with the code, unless I am overlooking something... Quote Link to comment Share on other sites More sharing options...
judkels Posted September 12, 2010 Author Report Share Posted September 12, 2010 Would you mind posting the full error that you are getting? Usually the error message tells you line numbers, showing where something was output to the browser. I'm not seeing anything else wrong with the code, unless I am overlooking something... This what I'm getting Warning: Cannot modify header information - headers already sent by (output started at /home/chilli/public_html/process.php:8) in /home/chilli/public_html/process.php on line 22 Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 12, 2010 Report Share Posted September 12, 2010 Hmm. According to the error, it still isn't liking your $headers variable for some reason. Try this... replace: $headers = "From: $email_from \n Reply-To: $email_from \n"; with: $headers = 'From: $email_from' . "\r\n" . 'Reply-To: $email_from; Just in case it makes any difference... I based this off the examples on http://php.net/manual/en/function.mail.php. If you are still having trouble with your code after doing this, would you mind posting the updated code you are using? Quote Link to comment Share on other sites More sharing options...
judkels Posted September 12, 2010 Author Report Share Posted September 12, 2010 Hmm. According to the error, it still isn't liking your $headers variable for some reason. Try this... replace: with: $headers = 'From: $email_from' . "\r\n" . 'Reply-To: $email_from; Just in case it makes any difference... I based this off the examples on http://php.net/manual/en/function.mail.php. If you are still having trouble with your code after doing this, would you mind posting the updated code you are using? No luck I.m afraid - well worse really Further below is my process.php page and this is the warning I'm now getting Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/chilli/public_html/process.php on line 15 Parse error: syntax error, unexpected ':' in /home/chilli/public_html/process.php on line 15 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>process</title> </head> <body> <?php $email_to = "email@xxxx.com"; $name = $_POST["name"]; $email_from = $_POST["email"]; $message = $_POST["message"]; $email_subject = "Feedback from website"; $headers = 'From: $email_from' . "\r\n" . 'Reply-To: $email_from; $message = "Name: ". $name . "\r\nMessage: " . $message; ini_set("sendmail_from", $email_from); $sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from); if ($sent) { header("Location: http://www.xxxxxx/thankyou.html"); } else { echo "There has been an error sending your comments. Please try later."; } ?> </body> </html> Bit of a mystery to me but this may make more sense to you thanks Judy Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 12, 2010 Report Share Posted September 12, 2010 Ah, ok, I figured it out. 1. I made a typo above - sorry! I missed adding in a closing quote which is why you are getting the different error: $headers = "From: $email_from" . "\r\n" . "Reply-To: $email_from"; (replace what you have with the code above.) 2. The source of your header issue though is this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>process</title> </head> <body> There's no need for that in the page -- you are sending information to the browser which is causing the error. You can remove everything before the "<?php" and after the "?>". Assuming there aren't any typos anywhere else, that should fix things for you. Quote Link to comment Share on other sites More sharing options...
judkels Posted September 12, 2010 Author Report Share Posted September 12, 2010 Thanks for all your help on this - I think I have now got it working - removing the code at the top of the page seemed to do the trick as much as anything. I am surprised about this as I'm sure it is on another page in another site and works fine but I'm going to double check this! I am going to get a couple of friends to send messages just to see if all is going ok. I shall now be on to the next snag before too long it's one little problem after another with this kind of stuff!. Many thanks for helping me. Judy Quote Link to comment Share on other sites More sharing options...
baja Posted September 13, 2010 Report Share Posted September 13, 2010 good work dude. I am having a problem with video conversion. where should i post it? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.