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">© Quinton Motor Club Ltd</div>
</html>
hope someone can spot the error
cheers pete ( not a php programmer at all)