我的数据库中有一张表,我有通过电子邮件发送的味精
这是我的代码
<?php
require_once 'lib/swift_required.php';
$con=mysqli_connect("localhost","root","","ex_smartcard");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = mysqli_query($con,"Select autosend.to,
autosend.cc,
autosend.bcc,
autosend.subject,
autosend.msg,
autosend.start,
autosend.expiry,
autosend.freq,
autosend.timestamp
From autosend
Where autosend.start <= CurDate() And autosend.expiry >= CurDate() And
autosend.freq = 3");
while($row = mysqli_fetch_assoc($query))
{
$to = $row['to'];
$cc = $row['cc'];
$subject = $row['subject'];
$emailBody="";
$emailBody .= $row['msg'];
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('192.168.0.1', 25)
->setUsername('smartcard@example.com')
->setPassword('123456')
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$message = Swift_Message::newInstance()
// Give the message a subject
->setSubject($subject)
// Set the From address with an associative array
->setFrom(array('smartcard@lotus.edu.in' => 'Lotus Reminder'))
// Set the To addresses with an associative array
->setTo(array($to))
// Using setCc() to set all recipients in one go
->setCc(array($cc))
// Give it a body
->setBody($emailBody)
;
$headers = $message->getHeaders();
// Send the message
$result = $mailer->send($message);
printf("Sent %d messages\n", $result);
echo $cc;
}
?>
$to = email1@example.com $cc = email2@example.com, email3@example.com
我收到此错误
Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [email1@example.com, email2@example.com] does not comply with RFC 2822, 3.6.2.' in C:\xampp\htdocs\PHPMailer\Swift\lib\classes\Swift\Mime\Headers\MailboxHeader.php:352 Stack trace: #0 C:\xampp\htdocs\PHPMailer\Swift\lib\classes\Swift\Mime\Headers\MailboxHeader.php(264): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('ishan@lotus.edu...') #1 C:\xampp\htdocs\PHPMailer\Swift\lib\classes\Swift\Mime\Headers\MailboxHeader.php(108): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array) #2 C:\xampp\htdocs\PHPMailer\Swift\lib\classes\Swift\Mime\Headers\MailboxHeader.php(65): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array) #3 C:\xampp\htdocs\PHPMailer\Swift\lib\classes\Swift\Mime\SimpleHeaderFactory.php(60): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array) #4 C:\xampp\htdocs\PHPMailer\Swift\lib\classes\Swift\Mime\SimpleHeaderSet.php(70): Swift_Mime_SimpleHeaderFactory->createMailboxHeader('Cc', A in C:\xampp\htdocs\PHPMailer\Swift\lib\classes\Swift\Mime\Headers\MailboxHeader.php on line 352
告诉我如何发送它们我在 cc 列中有许多用逗号分隔的邮件,我应该更改 mysql 中邮件的格式或更改代码。