お客様にメールを送信するスクリプトがあります。スクリプトの問題は複数のメールを送信することですが、複数の行の詳細を含む1つのメールを送信するだけです。すなわち、すべての請求書の詳細はテーブル内になければならない。複数の行を1つのメールに送信
は、以下の私のスクリプト
おかげ
$bill_status = "OVERDUE";
$st = $pdo->prepare("SELECT *, DATEDIFF(NOW(), due_date) AS days_diff
FROM bills LEFT JOIN login_details ON bills.user_id = login_details.user_id
WHERE bills.bill_status = '$bill_status'");
$st->execute();
$row_sent = $st->rowCount();
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'pasword'; // SMTP password
$mail->SMTPSecure = 'ssl';
$mail->Port = 465; // TCP port to connect to
$mail->From = '[email protected]';
$mail->FromName = 'Coy Name';
$mail->WordWrap = 587; // Set word wrap to 50 characters
$mail->AddEmbeddedImage("../img/logo.png", "logo");
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Notice';
while($rows = $st->fetch(PDO::FETCH_ASSOC)){
$username = $rows['username'];
$message= "
<div class='messages'>
<h3><img src='cid:my_logo'> </h3>
<br>
<div style='font-size:15px;'>Email Notification on Bill Due for Payment </h4>
<p>Dear: Customer</p>
<p>
The following bills are due for payment:
</p>
<table width='80%' border='0' cellspacing='0' cellpadding='0'>
<tr style='font-weight:bold;'>
<td>Trans Ref</td>
<td>Due Date</td>
<td>Days Overdue</td>
<td>Service Provider</td>
<td>Service Type</td>
<td>Amount Paid</td>
<td>Bill Status</td>
<td>Recurring</td>
</tr>
<h3>Yours<br>
Coy Name</h3>
";
$message .= " <tr>";
$message .= " <td>".$rows['trans_ref']."</td>";
$message .= " <td>".$rows['due_date']."</td>";
$message .= " <td>".$rows['days_diff']."</td>";
$message .= " <td>".$rows['service_provider']."</td>";
$message .= " <td>".$rows['service_type']."</td>";
$message .= " <td>".$rows['amount_paid']."</td>";
$message .= " <td>".$rows['bill_status']."</td>";
$message .= " <td>".$rows['recurring']."</td>";
$message .= " </tr>";
$mail->addAddress($username); // Add a recipient
$mail->Body = $message;
$mail->send();
$mail->ClearAddresses();
}
メール送信機能をループ内に置く...この事実から始める。 –
を置き換え、これをプレースホルダ 'WHERE bills.bill_status = '$ bill_status'")に置き換えてください; –
$メッセージヘッダを作成してから、すべての行をループします($ rows = $ st-> fetch(PDO :: FETCH_ASSOC)){ "$ mail-> addAddress($ username);' stuffを実行した後、SQLは1つのデータのみをロードしますか? 'username'? – JustOnUnderMillions