2016-07-13 3 views
-5

ich eine E-Mail für mehr als einen Empfänger senden mag automatisch jede Tag 08.00 Uhr Ausgabe des folgenden SQL-AbfragePHP für eine E-Mail für mehr als einen Empfänger sendet automatisch zu einem bestimmten Zeitpunkt

$sql10 ="SELECT  `X`.`wdate`,`X`.`line`,`X`.`style_no`,`X`.`po_no`,`P`.`order_qty`,`X`.`Line_O ut`,`X`.`Final_QC_Out`,`X`.`Iron_Out`,`X`.`Refinal_Out`,`X`.`Packing_In`,`X`.  `Warehouse_In` FROM(SELECT  `Q`.`wdate`,`Q`.`line`,`Q`.`style_no`,`Q`.`po_no`,SUM(IF(`Q`.`place`='Line_Ou t',`Q`.`bsum`,0)) AS Line_Out,  SUM(IF(`Q`.`place`='Final_QC_Out',`Q`.`bsum`,0)) AS  Final_QC_Out,SUM(IF(`Q`.`place`='Iron_Out',`Q`.`bsum`,0)) AS Iron_Out, SUM(IF(`Q`.`place`='Refinal_Out',`Q`.`bsum`,0)) AS Refinal_Out, SUM(IF(`Q`.`place`='Packing_In',`Q`.`bsum`,0)) AS Packing_In, SUM(IF(Q.place='Warehouse_In',Q.bsum,0)) AS Warehouse_In FROM(SELECT `T`.`fac_code` , T.style_no , T.po_no , SUM(T.bcount) AS bsum , `T`.`wdate` , `T`.`Place`,`T`.`line` FROM (SELECT `W`.`fac_code` , `W`.`barcode_id` , `B`.`style_no` , `B`.`po_no` , `B`.`size` , `B`.`colour` , COUNT(`W`.`barcode_id`) as `bcount`,`W`.`wdate`,`W`.`place`,`W`.`line` FROM wherin_tbl AS W , barcode_tbl AS B WHERE `W`.`barcode_id` = `B`.`barcode_id` GROUP BY `W`.`barcode_id` ,`W`.`fac_code`,`W`.`place`,`W`.`line`,`W`.`wdate`) AS T WHERE `T`.`fac_code`='$_POST[fac_code]' AND `T`.`wdate` BETWEEN '$_POST[frdate]' AND '$_POST[trdate]' GROUP BY `T`.`line`,`T`.`place`,`T`.`po_no`,`T`.`wdate`) AS Q GROUP BY `Q`.`wdate`,`Q`.`po_no`,`Q`.`line`) as X, po_tbl AS P WHERE `X`.`po_no`=`P`.`po_no` AND `P`.`fac_code`='$_POST[fac_code]' ORDER BY `X`.`wdate`,`X`.`line`"; 

My Script:

<?php 
echo "<table border='1' cellpadding='3' cellspacing='0'> "; 
echo "<tr> <th>Date</th><th>Line</th> <th>Style No</th> <th>PO No</th><th bgcolor='#CCCCFF'>Order Qty</th><th>Line Out</th><th>Final QC Out</th><th>Iron Out</th><th>Refinal Out</th><th>Packing In</th><th>Warehouse In</th>"; 
while ($row10=mysql_fetch_array($result10)){ 
echo "<tr>"; 
echo "<td>" . $row10['wdate'] . "</td>"; 
echo "<td> Line" . $row10['line'] . "</td>"; 
echo "<td>" . $row10['style_no'] . "</td>"; 
echo "<td>" . $row10['po_no'] . "</td>"; 
echo "<td bgcolor='#CCCCFF'>" . $row10['order_qty'] . "</td>"; 
echo "<td>" . $row10['Line_Out'] . "</td>"; 
echo "<td>" . $row10['Final_QC_Out'] . "</td>"; 
echo "<td>" . $row10['Iron_Out']. "</td>"; 
echo "<td>" . $row10['Refinal_Out'] . "</td>"; 
echo "<td>" . $row10['Packing_In'] . "</td>"; 
echo "<td>" . $row10['Warehouse_In'] . "</td>"; 
echo "</tr>"; 
} 

echo "</table>"; 

?> 

Datenbankstruktur für E-Mail-Adresse:

email_tbl 
sn | email   |location | 
1 |[email protected] | HO  | 
2 |[email protected] |TGK  | 
3 |[email protected] |HO  | 
+3

"pls senden Sie mir PHP-Codes für tun es" nein. –

+1

Bitte hör auf zu notieren wie "grüße bla bla" etc. Das hilft nicht weiter. – Gogol

Antwort

0

Dieses Skript sollte Ihr unmittelbares Problem lösen.

Der erste Block, der $ msg erstellt, basiert auf dem Code, den Sie zur Verfügung gestellt haben, da ich nicht genügend Einblick in Ihr Datenbank-Setup habe, um etwas moderneres zu schreiben. mysql_fetch_array und die gesamte Gruppe von mysql_functions wurden in PHP 5.5.0 veraltet (siehe http://php.net/manual/en/function.mysql-fetch-array.php, http://php.net/manual/en/function.mysql-query.php, etc.) und sollten nicht mehr verwendet werden. Aber da Sie die Datenbank auf diese Weise geöffnet haben, verwende ich sie auch im zweiten Codeblock. Bitte denken Sie darüber nach, sich mit der PDO-Klasse vertraut zu machen, was eine enorme Verbesserung darstellt und Ihre PHP/SQL-Version stabiler macht (http://php.net/manual/en/class.pdostatement.php).

$msg = "<table border='1' cellpadding='3' cellspacing='0'> "; 
$msg .= "<tr> <th>Date</th><th>Line</th> <th>Style No</th> <th>PO No</th><th bgcolor='#CCCCFF'>Order Qty</th><th>Line Out</th><th>Final QC Out</th><th>Iron Out</th><th>Refinal Out</th><th>Packing In</th><th>Warehouse In</th>"; 
while ($row10 = mysql_fetch_array($result10)) { 
    $msg .= "<tr>"; 
    $msg .= "<td>" . $row10['wdate'] . "</td>"; 
    $msg .= "<td> Line" . $row10['line'] . "</td>"; 
    $msg .= "<td>" . $row10['style_no'] . "</td>"; 
    $msg .= "<td>" . $row10['po_no'] . "</td>"; 
    $msg .= "<td bgcolor='#CCCCFF'>" . $row10['order_qty'] . "</td>"; 
    $msg .= "<td>" . $row10['Line_Out'] . "</td>"; 
    $msg .= "<td>" . $row10['Final_QC_Out'] . "</td>"; 
    $msg .= "<td>" . $row10['Iron_Out']. "</td>"; 
    $msg .= "<td>" . $row10['Refinal_Out'] . "</td>"; 
    $msg .= "<td>" . $row10['Packing_In'] . "</td>"; 
    $msg .= "<td>" . $row10['Warehouse_In'] . "</td>"; 
    $msg .= "</tr>"; 
} 
$msg .= "</table>"; 

$query = "SELECT email FROM email_tbl"; 
if (!$result = mysql_query($query)) { 
    $message = 'Invalid query: ' . mysql_error() . "\n"; 
    $message .= 'Whole query: ' . $query; 
    die($message); 
} 
$to = ''; 
while ($row = mysql_fetch_assoc($result)) { 
    $to .= $row['email'] . ','; 
} 
rtrim($to, ","); 
mysql_free_result($result); 

$subject = "Morning email from Gayan"; 

$headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: [email protected]'; 

if (mail($to, $subject, $msg, $headers)) { 
    echo "Email sent successfully<br>"; 
} else { 
    echo "ERROR sending email<br>"; 
} 
+0

Warnung: mail(): "sendmail_from" nicht in php.ini eingestellt oder benutzerdefinierte "From:" - Header fehlt in C: \ AppServ \ www \ VOGUE \ productionreport47.php in Zeile 93 Fehler beim Senden E-Mail ...... ..Ablauffehler aufgetreten .................. –

+0

Zeile 93 ist ................. if (Mail ($ to , $ subject, $ msg)) { –

+0

Hi .... Ben Shoval, Könnten Sie bitte unterstützen, um oben genannten Fehler auch zu lösen. –

Verwandte Themen