i have encountered issues on sending group mail in below code. error fatal error:
cannot redeclare clean_string() (previously declared in /home/content/83/11173683/html/aa/sendcanteen.php:74)
<?php $d = $_request['date']; //requesting date canteendetails.php include("dboperation.php"); $obj = new dboperation(); $n = array(); $e = array(); $str = "select * employee2"; $result = $obj->selectquery($str); while ($r = mysql_fetch_assoc($result)) { $n[] = $r['emp_name']; $e[] = $r['email']; } ($i = 0; $i < sizeof($n); $i++) { $str1 = "select * modifycanteen name='$n[$i]' , date='$d'"; $result1 = $obj->selectquery($str1); $r = mysql_fetch_assoc($result1); $email_to = $r['email']; $coffee = $r['coffee']; $tea = $r['tea']; $remarks = $r['remarks']; $email_subject = "canteen details"; $email_from = "catering services"; $body = ' <html> <head> <style> body, p.msonormal, li.msonormal { background-position: top; background-color: #336699; margin-left: 10em; margin-top: 1em; font-family: "verdana"; font-size: 10pt; font-weight:bold ; color: "000000"; } </style> </head> </body> '; $message = "mr/mrs " . $n[$i] . "\nyour canteen details"; $c = "no: of coffee :" . $coffee . "\n "; $t = "no: of tea :" . $tea . "\n "; $rem = "remarks :" . $remarks . "\n "; $bodys .= "$message<br>"; $bodys .= "$c<br>"; $bodyss .= "$t<br>"; $bodysss .= "$rem"; $body = $body . $bodys . $bodyss . $bodysss; function clean_string($string) { $bad = array( "content-type", "bcc:", "to:", "cc:", "href" ); return str_replace($bad, "", $string); } $email_message .= "message: " . clean_string($message) . "\n"; $headers = 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html;charset=iso-8859-1' . "\r\n"; $headers .= 'from: accounttoall.com <http://www.redboat.in/>' . "\r\n"; @mail($email_to, $email_subject, $body, $headers); } if (@mail) { header("location:canteendetails.php"); } else { echo "mail not sent"; } ?>
a function can define once
why define functino clean_string
in loop?
you must define function outside of loop
try this
<?php function clean_string($string) { $bad = array( "content-type", "bcc:", "to:", "cc:", "href" ); return str_replace($bad, "", $string); } $d = $_request['date']; //requesting date canteendetails.php include("dboperation.php"); $obj = new dboperation(); $n = array(); $e = array(); $str = "select * employee2"; $result = $obj->selectquery($str); while ($r = mysql_fetch_assoc($result)) { $n[] = $r['emp_name']; $e[] = $r['email']; } ($i = 0; $i < sizeof($n); $i++) { $str1 = "select * modifycanteen name='$n[$i]' , date='$d'"; $result1 = $obj->selectquery($str1); $r = mysql_fetch_assoc($result1); $email_to = $r['email']; $coffee = $r['coffee']; $tea = $r['tea']; $remarks = $r['remarks']; $email_subject = "canteen details"; $email_from = "catering services"; $body = ' <html> <head> <style> body, p.msonormal, li.msonormal { background-position: top; background-color: #336699; margin-left: 10em; margin-top: 1em; font-family: "verdana"; font-size: 10pt; font-weight:bold ; color: "000000"; } </style> </head> </body> '; $message = "mr/mrs " . $n[$i] . "\nyour canteen details"; $c = "no: of coffee :" . $coffee . "\n "; $t = "no: of tea :" . $tea . "\n "; $rem = "remarks :" . $remarks . "\n "; $bodys .= "$message<br>"; $bodys .= "$c<br>"; $bodyss .= "$t<br>"; $bodysss .= "$rem"; $body = $body . $bodys . $bodyss . $bodysss; $email_message .= "message: " . clean_string($message) . "\n"; $headers = 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html;charset=iso-8859-1' . "\r\n"; $headers .= 'from: accounttoall.com <http://www.redboat.in/>' . "\r\n"; @mail($email_to, $email_subject, $body, $headers); } if (@mail) { header("location:canteendetails.php"); } else { echo "mail not sent"; } ?>