Forum Moderators: coopster

Message Too Old, No Replies

php problem with data pickup (i think)

         

peten

8:33 pm on Mar 14, 2011 (gmt 0)

10+ Year Member



Hi folks/php gurus

I have a php script and html page combination for error and problem reporting but i can not get it to function correctly it fails every time to pick up the name field

script below
<?php

$title = $_REQUEST['title'] ;

$name = $_REQUEST['name'] ;

$comments = $_REQUEST['comments'] ;



//prevent email strings

if((strpos($name, '@')!==false) || strlen($email)>50 || strlen($name)>30 )

die();



//prevent bad strings

function contains_bad_str($str_to_test) {

$bad_strings = array(

"content-type:",

"mime-version:",

"multipart/mixed",

"Content-Transfer-Encoding:",

"bcc:","cc:",

"to:" );



foreach($bad_strings as $bad_string) {

if(eregi($bad_string, strtolower($str_to_test))) {

echo "$bad_string found. Suspected injection attempt - mail not being sent. If you are trying to inject spam or other junk unfortunatley it will not work no Windows here.";

exit;

}

}

}



function contains_newlines($str_to_test) {

if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) {

echo "newline found in $str_to_test. Suspected injection attempt - mail not being sent. If you are trying to inject spam or other junk unfortunatley it will not work no Windows here.";

exit;

}

}



contains_bad_str($name);

contains_bad_str($email);

contains_newlines($name);

contains_newlines($email);



if (!isset($_REQUEST['email'])) {

header( "Location: contact.html" );

}

elseif (empty($email) || empty($phone)) {

header( "Location: noemail.html" );

}



mail( "qweb@btinternet.com", "Site Problem Report",

"$message\ntitle: $title \ncomments: $comments",

"From: $name <$email>" );

header( "Location: thankyou.html" );



?>


and the web page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<title>About QMC</title>
<meta name="generator" content="Bluefish 2.0.2" >
<meta name="author" content="pete" >
<meta name="date" content="2011-03-14T11:08:29+0000" >
<meta name="copyright" content="Quinton Motor Club Ltd">
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="ROBOTS" content="INDEX, FOLLOW">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="expires" content="0">
<link rel="shortcut icon" href="../Art/favicon.ico" type="image/vnd.microsoft.icon">
<link href="../qmc.css" rel="stylesheet" type="text/css">

<link rel="stylesheet" href="inc/main.css" type="text/css">

<script language=JavaScript>;







function test(src) {



var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";



var regex = new RegExp(emailReg);



return regex.test(src);



}







function buildMessage(){







var MsgBody,mailfields,tempString;



var testString;



testString = new String;



MsgBody = "";







document.mailForm.TempValue.value = MsgBody;







var a,b,c,varName,varValue



tempString = document.mailForm.mailfields.value ;







mailfields = tempString.split(",");



b = "test";



for (a in mailfields){







c = "";



varName = "";



varValue = "";



varName = mailfields[a].replace(/ /g, "") ;







varValue = eval("document.mailForm." + varName + ".value")







if ( -1 != varName.indexOf("_CB")){







varValue = eval("document.mailForm." + varName + ".checked") ;











}







MsgBody = MsgBody + varName.replace(/_/g, " ").toUpperCase() + " : " + varValue + "\n";







}









document.mailForm.TempValue.value = MsgBody;



document.mailForm.submit();







}







function checkScript(){















if (!validate_email(document.mailForm.mailfrom.value)){



alert("A VALID EMAIL ADDRESS HAS TO BE SPECIFIED.");



return false;



alert("here")



}



// OTHER CHECKS





buildMessage()







return false;



}



function validate_email(email) {







var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";



var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";







var reg1 = new RegExp (reg1str);



var reg2 = new RegExp (reg2str);







if (reg1.test(email) || !reg2.test(email)) {



return false;



}







return true;



}



















</script>

</head>

<body class="body" >
<table width="25%" border="0" cellspacing="0" cellpadding="4" summary="qmc">
<tr>
<td width="20%"><img src="../Art/logo-trans.png" width="120" height="120" alt="logo"></td>
</tr>
</table>

<table border="0" cellspacing="0" cellpadding="0" align="center">



<tr>

<td valign="top" class="cellpad">

<table width="610" border="0" cellspacing="0" cellpadding="0" align="center">

<tr>

<td>

<table border="0" cellpadding="0" cellspacing="0" width="470" align="center">

<tr>

<td width="100%" colspan="2" valign="top" align="left" class="text1"><br>

<form name="form1" method="post" action="qmcrep.php">

<table width="100%" border="0">

<tr>

<td colspan="2">To report a problem use the entry form below;</td>

</tr>

<tr>

<td>Title : </td>

<td><select name="title" id="title">

<option>Mr</option>

<option>Mrs</option>

<option>Miss</option>

<option>Ms</option>

<option>Dr</option>

</select></td>

</tr>

<tr>

<td>Name : </td>

<td><input name="name" type="text" id="name"></td>

</tr>

<tr>

<td>Email address : </td>

<td><input name="email" type="text" id="email"></td>

</tr>

<tr>

<td colspan="2"><div align="center">

<textarea name="comments" cols="70" rows="15" id="comments">Please describe the problem you are having here</textarea>

</div></td>

</tr>

<tr>

<td colspan="2"><div align="center">

<input type="submit" name="Submit" value="Send your problem report"></div></td>

</tr>

</table>

</form>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr align="left" valign="top">

<td class="font1" colspan="2"><a href="mailto:qweb@btinternet.com?Subject=website%20problem%20report..." target="_blank"><br>

</a></td>

</tr>

</table>

</td>

</tr>

</table>

</td>

</tr>

</table>

</td>

</tr>

</table>
<p class="style4"><a href="../index.shtml" > Home Page </a></p>
</body>
<div class="copr">&copy; Quinton Motor Club Ltd</div>

</html>


hope someone can spot the error

cheers pete ( not a php programmer at all)

coopster

8:24 pm on Mar 17, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you certain that the $_REQUEST superglobal is populated? Have you tried dumping that first in your script because that is where your $name value is coming from. Place something like this right before you attempt to use the $_REQUEST variable to see if it is populated with the values you expect.
print '<pre>'; 
print_r($_REQUEST);
print '<pre>';
exit;

peten

8:45 pm on Mar 17, 2011 (gmt 0)

10+ Year Member



ok thanks i'll give it a try the confusing part is the script works on another site as a booking form system i have the original scripts as well all i have taken out is the un needed fields such as address tel numbers diet ect

Thanks pete .

peten

9:53 pm on Mar 17, 2011 (gmt 0)

10+ Year Member



ok update on this one it picks up the title field ok it picks up the comments field but not name

coopster

1:48 pm on Mar 19, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



When the form is displayed in the browser, have you tried "View Source" and then copy/paste the html into the validator [validator.w3.org]?

peten

3:49 pm on Mar 19, 2011 (gmt 0)

10+ Year Member



Hum well ran it thru a few glitches sorted but still the same result this is what i get back
"title: Mr
comments: Please describe the problem you are having here re tewst new DTD type " no name field there is still 1 small error but it is outside of the function of the page a complaint about the position of a <div> statement but it is down there on purpose

pete .
still confusticated

coopster

6:00 pm on Mar 19, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well, there is no phone in your HTML form that you refer to here ...

elseif (empty($email) || empty($phone)) {

... and you never do set the $email variable. I see $title, $name and $comments at the top of your script, but no $email. No $message either.

Another issue, you may or may not get the following error from your internet message transfer agent (qmail, etc.):
Warning: mail() [function.mail]: SMTP server response: 451 See [pobox.com...]
That link will bring you here, where you can read up on bare linefeeds:
[cr.yp.to...]

You may need to add a carriage return (CR) in your message:

"$message\r\ntitle: $title\r\ncomments: $comments",

... and lastly, you are indeed getting the name field back in your form, it's just that you are not using it in your email message. Try adding it between the title and comments:

"$message\r\ntitle: $title\r\nname: $name\r\ncomments: $comments",

peten

6:55 pm on Mar 19, 2011 (gmt 0)

10+ Year Member



I thank you sir thats fixed it thanks muchly

the complete web site is qmc.org.uk or quinton-mc.org.uk
that i have just built from the ground up for my car club so thanks lot ..

Pete .