Cannot redeclare clean_string() (previously declared in

[font=verdana][size=12pt][/size][/font]
Hi there,
I am stuck with mailing functionality in php, please help me out
Im trying to send mail to many , i included mail id’s into one variable , and im getting mail id’s thorough for loop ( SELECT FROM Table),
Problem is , i can send mail to one person and its delivered … but when selected multiple or more than one person its giving an error Cannot redeclare clean_string() (previously declared in …
I thikn its problem with for loop …
Please help …
code

if(isset($_POST[‘submit’]))
{
$txtMessage=mysql_real_escape_string($_POST[‘txtMessage’]);
$txtStu=$_POST[‘txtStuFname’];

for($i=0;$i<$e;$i++)
{
echo “”;
echo "THE VALUE OF ".$i;
echo “”;
echo $txtStu[$i];
echo “”;
//echo "SELECT stu_email FROM stu_registration WHERE stu_fname=’$txtStu[$i]’ ";
$queryelist=mysql_query("SELECT stu_email FROM stu_registration WHERE stu_fname=’$txtStu[$i]’ ");

$elist=mysql_fetch_array($queryelist);

echo "Email is ".$elist[‘stu_email’];

$email_to =$elist['stu_email'];
echo "Email To ".$email_to;


	$email_subject = "Student SMS :";
	$email_from = "[email protected]";
 
function clean_string($string)
 {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);

}
$email_message .= “$txtStu[$i] , Your SMS : “.clean_string($txtMessage).”\n”;
//$email_message .= “Student SMS: “.($txtMessage).”\n”;

$headers = 'From: '.$email_from."\r\n".
$headers .= “To:<”.$email_to.">\n";
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
if (!$con)
{
echo “sorry”;
die('Could not connect: ’ . mysql_error());
}

$query=mysql_query("INSERT INTO student_sms(student_message)VALUES('$txtMessage')");
if($query)
{
	echo "</br>";
	echo "Student mail Sent!";
}
else
{
	echo "mail not Sent";
}

I hope some one understands what i wrote and what my problem is …

You shouldn’t be having your function inside a while loop, instead put the function outside of the loop, a function with the same name cannot occur more than once on a page.

Try this:

[php]
function clean_string($string)
{
$bad = array(“content-type”,“bcc:”,“to:”,“cc:”,“href”);
return str_replace($bad,"",$string);
}

if(isset($_POST[‘submit’]))
{
$txtMessage=mysql_real_escape_string($_POST[‘txtMessage’]);
$txtStu=$_POST[‘txtStuFname’];

for($i=0;$i<$e;$i++)
{
echo “”;
echo "THE VALUE OF ".$i;
echo “”;
echo $txtStu[$i];
echo “”;
//echo "SELECT stu_email FROM stu_registration WHERE stu_fname=’$txtStu[$i]’ ";
$queryelist=mysql_query("SELECT stu_email FROM stu_registration WHERE stu_fname=’$txtStu[$i]’ ");

$elist=mysql_fetch_array($queryelist);

echo "Email is ".$elist[‘stu_email’];

$email_to =$elist[‘stu_email’];
echo "Email To ".$email_to;

   $email_subject = "Student SMS :";
   $email_from = "[email protected]";

$email_message .= “$txtStu[$i] , Your SMS : “.clean_string($txtMessage).”\n”;
//$email_message .= “Student SMS: “.($txtMessage).”\n”;

$headers = 'From: '.$email_from."\r\n".
$headers .= “To:<”.$email_to.">\n";
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
if (!$con)
{
echo “sorry”;
die('Could not connect: ’ . mysql_error());
}

$query=mysql_query(“INSERT INTO student_sms(student_message)VALUES(’$txtMessage’)”);
if($query)
{
echo “”;
echo “Student mail Sent!”;
}
else
{
echo “mail not Sent”;
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service