こんにちは、MySQL からデータを取得してメールで送信するスクリプトを作成しました。HTML コンテンツ タイプを使用しています。出力 HTML コンテンツのフォーマットに問題があります。
これが私のコードです
<?php
$con=mysqli_connect("host","user","pwd","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . Mysqli_connect_error();
}
$result3 = mysqli_query($con,"SELECT cardnumber, email, firstname, surname, GROUP_CONCAT(borrowernumber) as borrowernumber, GROUP_CONCAT(issuedate) as issuedate, GROUP_CONCAT(date_due) as date_due, GROUP_CONCAT(barcode) as barcode, GROUP_CONCAT(title SEPARATOR '//') as Title, GROUP_CONCAT(author SEPARATOR '/') as Author FROM issuestestmail GROUP BY email");
while($row = mysqli_fetch_array($result3))
{
$to = $row['email'];
$emailBody="<html><body><font face='arial' size='2'>";
// explode the Pin/balances on the comma's
$borrowernumber = explode(',',$row['borrowernumber']);
$barcode = explode(',',$row['barcode']);
$issuedate = explode(',',$row['issuedate']);
$date_due = explode(',',$row['date_due']);
$Title = explode('//',$row['Title']);
$Author = explode('/',$row['Author']);
$subject = "List of Issued Books ( Total : ".count($barcode).")";
// Create a line for each item/balance
$emailBody .= "<b>Dear,</b> ".$row['firstname']." ".$row['surname']." (" ."<b>ID:</b> <b>".$row['cardnumber']."</b>)<br/><br/>"."\r\n"."Kindly find the list of library items which are currently issued on your account"."<br/><br/>";
$emailBody .= "<b>Total no of issued books:</b> ".count($barcode)."<br/><br/>";
foreach($borrowernumber as $key => $borrowernumber){
$emailBody .= "<table border='0' width='100%' id='table1' style='border-width: 0px; font-size:14px'><tr>";
$emailBody .= "<td width='100' style='border-style: none; border-width: medium'><b>Barcode</b></td>";
$emailBody .= "<td style='border-style: none; border-width: medium'>: ".$barcode[$key]."</td>";
$emailBody .= "</tr></table>";
$emailBody .= "<table border='0' width='100%' id='table2' style='border-width: 0px; font-size:14px'><tr>";
$emailBody .= "<td width='100' style='border-style: none; border-width: medium'><b>Title</b></td>";
$emailBody .= "<td style='border-style: none; border-width: medium'>: ".$Title[$key]."</td>";
$emailBody .= "</tr></table>";
$emailBody .= "<table border='0' width='100%' id='table3' style='border-width: 0px; font-size:14px'><tr>";
$emailBody .= "<td width='100' style='border-style: none; border-width: medium'><b>Author</b></td>";
$emailBody .= "<td style='border-style: none; border-width: medium'>: ".$Author[$key]."</td>";
$emailBody .= "</tr></table>";
$emailBody .= "<table border='0' width='100%' id='table4' style='border-width: 0px; font-size:14px'><tr>";
$emailBody .= "<td width='100' style='border-style: none; border-width: medium'><b>Issue date</b></td>";
$emailBody .= "<td style='border-style: none; border-width: medium'>: ".$issuedate[$key]."</td>";
$emailBody .= "</tr></table>";
$emailBody .= "<table border='0' width='100%' id='table5' style='border-width: 0px; font-size:14px'><tr>";
$emailBody .= "<td width='100' style='border-style: none; border-width: medium'><b>Due Date</b></td>";
$emailBody .= "<td style='border-style: none; border-width: medium'>: ".$date_due[$key]."</td>";
$emailBody .= "</tr></table><br/><hr><br/>";}
// add a Total Balance line
$emailBody .= "<br/><br/><b>Library</b><br/>xyz<br/>";
$emailBody .= "</font></body></html>";
$headers = "From: Library@lotus.edu.in\r\n";
$headers .= "Reply-To: Library@lotus.edu.in\r\n";
$headers .= "Return-Path: Library@lotus.edu.in\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
if(mail($to, $subject, $emailBody, $headers)) {
echo $emailBody;
echo 'Email sent successfully!<br/><br/>';
} else {
echo $emailBody;
die('Failure: Email was not sent!');
}
}
mysqli_close($con);
?>
このメールの出力は、gmail では次のようになります。
すべて問題ありませんが、レコード record no 3 ""< table border='0' width='100%' ID='table3' style='border-width: 0px; の 1 つでエラーが発生します。font-size:14px'>""