Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mail function errors

    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:
    Code:
    function valid_email($address)
    The complete portion of code (below //Mail things) which is inserted in my (one) php page is this:

    Code:
    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.
    Last edited by jolene; 11-27-2006 at 10:43 PM.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    PHP Code:
    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?

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 :
    Code:
    mail($to, $subject, $message, $headers);
    with
    Code:
    function send_mail($email)

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    get ride of the 'function' keyword then

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    Code:
    // 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
    Last edited by jolene; 12-06-2006 at 09:57 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •