...

View Full Version : Mail function errors



jolene
11-27-2006, 10: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.

GJay
11-28-2006, 12:29 AM
function send_mail($email)

is a function definition with no content, are you trying to call the function? (lose the 'function' keyword) or is it a definition you've copied from somewhere and messed up?

jolene
11-28-2006, 09:52 PM
yes, it's code that someone gave me, but I don't know exactly how I should modify and insert it...
the idea was to replace this line :

mail($to, $subject, $message, $headers);
with


function send_mail($email)

GJay
11-29-2006, 02:53 PM
get ride of the 'function' keyword then

jolene
12-06-2006, 09:30 AM
Now the mails dont get sent. How can modify the code to have the return mails sent and to get the anti-spam code working correctly?


// Mail things


$to = "jkbcn@hotmail.com, kellybcn@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;
}
}
}

?>

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum