Jump to content

Error on line 24 - PHP Contact Form with Captcha


Narutio

Recommended Posts

Hey guys.

Im a noob here, and also on PHP.

anyways my problem is im trying to enter the captcha value wrong so i can see what message i get (and also to see if everything works).

 

i got the codes from this site and i havent change any coding only the email.

This is the error msg im getting

"Warning: Header may not contain more than a single header, new line detected. in /home/egyptian/public_html/mailer.php on line 24"  i have wrote in the code where line 24 is. using. before the doctype.

 

The code im using is :

 

<?php


// load the variables form address bar
$subject = $_REQUEST["subject"];
$message = $_REQUEST["message"];
$from = $_REQUEST["from"];
$verif_box = $_REQUEST["verif_box"];
// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message); 
$subject = stripslashes($subject); 
$from = stripslashes($from); 
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if verification code was correct send the message and show this page
mail("[email protected]", 'Online Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "From: $from");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
} else {
// if verification code was incorrect then return to contact page and show error
<This is line 24> header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
}
?>
<!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=iso-8859-1" />
<title>E-Mail Sent</title>
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style></head>

<body>l
Email sent. Thank you.<br />
<br />
Return to <a href="/">home page</a> ? 
</body>
</html>

 

 

 

Im sorry i dont know how to paste code with line number.. I hope someone can help me with this error and also enlighten me how to copy with line numbers. haha

 

Thanks in advance guys & girls

The problem is actually given in the error message - one of the variables in your query string (i would guess $message) contains a new line and this cannot be present in the header redirect. You can get around this by using the url_encode() function on the variables before you put them in the query string and then use the url_decode() function when you want to use the variables.

 

However, i better solution would be to not perform a redirect at all. You're redirecting to the current page so I assume you're form is on the same page as the processing? In which case, you should just be able to alter your logic so that the form is redisplayed with the information filled in if there is an error.

Thanks for your reply, but i am a noob in php.

so i dont understand this & i know i sudnt be using php if i dont know how to use it, all i did was copy the code from another site where it works but i cant get it to work. i just wanted to use a script for the contact info page.

is this what you mean?

 

 header("Location:".$_SERVER['HTTP_REFERER'];urlencode("?subject=$subject&from=$from&message=$message&wrong_code=true");
    exit;

Not quite. I mean like this:

 

header("Location:".$_SERVER['HTTP_REFERER'].urlencode("?subject=$subject&from=$from&message=$message&wrong_code=true"));

 

However, you'll also need to use the urldecode function on the variables on the page that you are redirecting to.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.