- This topic is empty.
-
AuthorPosts
-
July 27, 2014 at 8:40 pm #176636
npuffer
ParticipantI have a form issue. This is a clients site and the email form was already set up when I took over. I didnt bother messing with it since it worked. Her hosting company did a big server update and now her form isnt working 100%. The issue is with the Thank You page, it wont show up. Can someone take a look and see if they can tell what the problem is? I have messes around with it but I just cant see what the problem is.
This is the contact.php page
<?php
/* Set e-mail recipient */
$myemail = “[email protected]”;/* Check all form inputs using check_input function */
$yourname = check_input($_POST[‘yourname’], “Your Name”);
$subject = check_input($_POST[‘subject’], “The Subject”);
$email = check_input($_POST[’email’], “Your Email Address”);
$comments = check_input($_POST[‘comments’], “Your Comments/Questions”);/* If e-mail is not valid show error message */
if (!preg_match(“/([\w-]+\@[\w-]+.[\w-]+)/”, $email))
{
show_error(“E-mail address not valid”);
}/* Let’s prepare the message for the e-mail */
$message = “Hello Evelyn!An email has been submitted by:
Name: $yourname
E-mail: $emailComments:
$comments“;
/* Send the message using mail() function */
mail($myemail, $subject, $message);/* Redirect visitor to the thank you page */
header(“Location: thanks.html”);
exit();/* Functions we used */
function check_input($data, $problem=”)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}function show_error($myError)
{
?>
<html>
<body><b>Oops, you forgot to include:</b><br />
<?php echo $myError; ?></body> </html>
<?php
exit();
}
?>Theres a second <body> and <html> take in here, I took it out and that didnt make a difference. Should it be there?
The website is evelynclarkdesigns dot com/contact.htm
Thanks,
nJuly 28, 2014 at 10:31 am #176703__
Participantheader(“Location: thanks.html”);
I don’t see this header after submitting the form. Something might be happening before it is set —does sending the
mail
work correctly? do you have error reporting enabled?This probably isn’t the cause of your immediate problem, but note that
Location
headers must use a fully qualified URL.header( 'Location: http://example.com/thanks.html' );
Relative paths might work in many cases, but it is less reliable and will not work at all in some browsers.
Also, please do not “dump” code on the forums. It is very difficult to read/navigate through and discourages people from trying to help. Small amounts of code necessary to describe a problem are fine, but make sure you use code blocks so they are properly formatted. If you need to share large amounts of code, use codepen or make a gist on github.
July 28, 2014 at 10:57 am #176705Harris Christiansen
ParticipantYou said her hosting company just did a big server update, I would agree with un-traq-ed and say its possible they updated their php version and now its requiring the fully qualified Location header.
Also make sure you are not outputting any text to the page before setting the Location header. It might help to turn on error reporting and see if something comes up.
error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('display_errors','On');
July 28, 2014 at 12:39 pm #176711__
Participantits possible they updated their php version and now its requiring the fully qualified Location header.
To clarify, it’s the header itself (the HTTP/1.1 protocol) that requires a fully qualified URL, not php’s
header
function. Other than associating certain keywords with HTTP response codes, I don’t believe php validates the headers you provide in any way.It could be useful, however, to know what version of PHP your host upgraded to.
Also make sure you are not outputting any text to the page before setting the Location header.
This is actually fairly likely, though I couldn’t tell by looking at your unformatted code. If your host used to have an automatic output buffer configured, it’s possible that the problem existed all along but was hidden until now.
July 28, 2014 at 9:10 pm #176722npuffer
ParticipantHi,
Thank you both for taking a look at my problem. I do apologize for dumping code. I’m new to the forum and I should have checked to see what the appropriate way to show code was.
I changed the location header to read
header('Location: http://evelynclarkdesigns.com/thanks.html');
<code></code>
But it didn’t fix the problem.I’m not sure what you mean by,
“Also make sure you are not outputting any text to the page before setting the Location header. ”Thanks,
nJuly 28, 2014 at 9:16 pm #176724npuffer
ParticipantSo cool!!! I added the error reporting code and this is what it said…
Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosnaweb01b/b2415/dot.evelynclarkdesigns/public_html/contact.php:14) in /hermes/bosnaweb01b/b2415/dot.evelynclarkdesigns/public_html/contact.php on line 53
<code></code>So it is the header location like you both are saying but I dont understand why it still wont work if I changed it as you both suggested.
July 28, 2014 at 9:53 pm #176729__
ParticipantSo cool!!! I added the error reporting
SO cool. Troubleshooting FTW. : )
I changed the location header … But it didn’t fix the problem.
No, I didn’t expect it to. That was kind of a “side note.” But it was a good idea to change it anyway.
Warning: Cannot modify header information - headers already sent
“headers already sent” means that there was already regular output sent to the browser — e.g., HTML, text, or even a blank line. HTTP responses look like this:
HTTP/1.1 200 OK Header_Name: Value Header_Name: Value <!doctype html> <html> <head> <meta charset=utf-8> <title>my web page</title> </head> <body> <p>See all the headers up there? <p>…no? </body> </html>
I’m sure you recognize the second part — it’s a normal HTML document. The first part (before the blank line) is where all the HTTP headers go. That’s where you put the response code,
Location
header, cookies, and so forth. Yes, it really is just plain text that is sent before the “body” of the response.The moment you send regular output to the browser —anything, even a blank line— PHP has to send all of the header information, because the regular output must go after, in the body. From this point forward, it is too late to add any more headers: they are “already sent.”
SO, you’ve got to figure out where that output is, and then either (a) remove it, or (b) move your call to
header
somewhere before that output.July 30, 2014 at 6:15 pm #177047npuffer
Participantun-traq-ed, You ROCK!!!
Thank you so much for sticking it out with me. I really appreciate it. Because of your patience and explanations I was able to fix the problem. There were spaces everywhere, as soon as I removed them it worked. It was like magic :)
BTW, Harris Christiansen, your pretty awesome too!
The the best,
NatashaJuly 30, 2014 at 11:01 pm #177068__
ParticipantYou’re welcome; glad you got it solved.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.