2015-04-28 4 views
0

Я столкнулся с некоторыми проблемами при отправке групповой почты в код ниже. Ошибка Фатальная ошибка:Отправка групповой почты с различными данными, выбранными из базы данных

Cannot redeclare clean_string() (previously declared in /home/content/83/11173683/html/AA/sendcanteen.php:74)

<?php 
$d = $_REQUEST['date']; //requesting date from canteendetails.php 

include("dboperation.php"); 
$obj = new dboperation(); 
$n  = array(); 
$e  = array(); 
$str = "select * from employee2"; 
$result = $obj->selectquery($str); 
while ($r = mysql_fetch_assoc($result)) { 
    $n[] = $r['emp_name']; 
    $e[] = $r['email']; 
} 
for ($i = 0; $i < sizeof($n); $i++) { 

    $str1  = "select * from modifycanteen where name='$n[$i]' and 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 IS NOT SENT";  
} 
?> 

ответ

0

функция может определить только один раз

почему вы определяете functino clean_string в течение цикла?

вы должны определить функцию вне цикла для

попробовать это

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

$d = $_REQUEST['date']; //requesting date from canteendetails.php 

include("dboperation.php"); 
$obj = new dboperation(); 
$n  = array(); 
$e  = array(); 
$str = "select * from employee2"; 
$result = $obj->selectquery($str); 
while ($r = mysql_fetch_assoc($result)) { 
    $n[] = $r['emp_name']; 
    $e[] = $r['email']; 
} 
for ($i = 0; $i < sizeof($n); $i++) { 

    $str1  = "select * from modifycanteen where name='$n[$i]' and 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 IS NOT SENT";  
} 
?> 
+0

Спасибо за ваш ответ, что ошибка исправлена. но у меня проблема при отправке почты. я должен отправить каждого сотрудника на свои собственные данные. Но теперь он отправляет каждому сотруднику детали всем. Пожалуйста, помогите мне решить эту проблему. – mars

+0

если ваша ошибка исправлена ​​с этим ответом, сначала примите этот ответ и задайте новый вопрос – ashkufaraz

Смежные вопросы