jolene
11-27-2006, 09:50 PM
Hi,
I have some code to defend against spam etc and when I run it I get the following error:
Parse error: syntax error, unexpected T_FUNCTION, expecting '{' in /home/....t/public_html/phptest.php on line 462- in this line:
function valid_email($address)
The complete portion of code (below //Mail things) which is inserted in my (one) php page is this:
if ($_POST["question59"]=="C") $score++;
if ($_POST["question60"]=="D") $score++;
// Mail things
$to = "jkbcn@hotmail.com";
$subject = "Someone scored ". $score . " over ". $scoremax . ".";
$headers = "MIME-Version: 1.0 \r\n" ;
$headers .= "Content-Type: text/plain \r\n";
$headers .= "Cc: \r\n";
$headers .= "From: <Webmaster@profesornativo.com> \r\n\r\n";
$message = "From: ".$visitormail."\n\n";
function send_mail($email)
function valid_email($address)
{
// check an email address is possibly valid
if (ereg('^[a-zA-Z0-9 \._\-]+@([a-zA-z0-9\-]*\.)+[a-zA-Z]+$',$address))
{
return true;
}
return false;
}
//inititialise an error array
$errors = array();
//check the content submitted by the user
if(!valid_textfield($firstname))
{
$errors[] = 'Firstname must be filled in and contain text only.';
}
if(!valid_textfield($lastname))
{
$errors[] = 'Surname must be filled in and contain text only.';
}
if(!is_numeric($phone)||(strlen($phone)<6))
{
$errors[] = 'Phone number must be a number at least 6 digits long';
}
if(!valid_email($email))
{
$errors[] = 'Email Address must be in the following format - name@yourdomain.com';
}
//call the function to send the email
return send_email($to, $subject, $message, $headers);
function send_email($to, $subject, $message, $headers)
{
//remove any content type, mime type,
$to = clean_data($to);
$subject = clean_data($subject);
$message = clean_data($message);
$headers = clean_data($headers);
if(mail($to, $subject, $message, $headers))
{
return true;
}
else
{
return false;
}
}
function clean_data($text)
{
// Remove injected headers
$find = array("Content-Type:", "Mime-Type:", "Content-type:", "MIME-Type:");
$ret = str_replace($find, "**bogus header removed**", $text);
return $ret;
}
?>
<?php
if ($score <= 8)
{
?>
Any help greatly appreciated.
I have some code to defend against spam etc and when I run it I get the following error:
Parse error: syntax error, unexpected T_FUNCTION, expecting '{' in /home/....t/public_html/phptest.php on line 462- in this line:
function valid_email($address)
The complete portion of code (below //Mail things) which is inserted in my (one) php page is this:
if ($_POST["question59"]=="C") $score++;
if ($_POST["question60"]=="D") $score++;
// Mail things
$to = "jkbcn@hotmail.com";
$subject = "Someone scored ". $score . " over ". $scoremax . ".";
$headers = "MIME-Version: 1.0 \r\n" ;
$headers .= "Content-Type: text/plain \r\n";
$headers .= "Cc: \r\n";
$headers .= "From: <Webmaster@profesornativo.com> \r\n\r\n";
$message = "From: ".$visitormail."\n\n";
function send_mail($email)
function valid_email($address)
{
// check an email address is possibly valid
if (ereg('^[a-zA-Z0-9 \._\-]+@([a-zA-z0-9\-]*\.)+[a-zA-Z]+$',$address))
{
return true;
}
return false;
}
//inititialise an error array
$errors = array();
//check the content submitted by the user
if(!valid_textfield($firstname))
{
$errors[] = 'Firstname must be filled in and contain text only.';
}
if(!valid_textfield($lastname))
{
$errors[] = 'Surname must be filled in and contain text only.';
}
if(!is_numeric($phone)||(strlen($phone)<6))
{
$errors[] = 'Phone number must be a number at least 6 digits long';
}
if(!valid_email($email))
{
$errors[] = 'Email Address must be in the following format - name@yourdomain.com';
}
//call the function to send the email
return send_email($to, $subject, $message, $headers);
function send_email($to, $subject, $message, $headers)
{
//remove any content type, mime type,
$to = clean_data($to);
$subject = clean_data($subject);
$message = clean_data($message);
$headers = clean_data($headers);
if(mail($to, $subject, $message, $headers))
{
return true;
}
else
{
return false;
}
}
function clean_data($text)
{
// Remove injected headers
$find = array("Content-Type:", "Mime-Type:", "Content-type:", "MIME-Type:");
$ret = str_replace($find, "**bogus header removed**", $text);
return $ret;
}
?>
<?php
if ($score <= 8)
{
?>
Any help greatly appreciated.