我正在使用PHPMailer通过SMTP发送带有TLS加密的电子邮件。电子邮件发送正常并按预期收到。但由于某种原因,未显示每封电子邮件的收件人地址。我在这里做错了吗?
$mailer = new PHPMailer;
// header
$mailer->IsHTML(true);
$mailer->CharSet = "text/html; charset=UTF-8;";
$mailer->WordWrap = 80;
// protocol
$mailer->isSMTP(); // Set mailer to use SMTP
$mailer->SMTPDebug = 0;
$mailer->SMTPAuth = true; // Enable SMTP authentication
// credential
$mailer->SMTPSecure = 'tls'; // Enable encryption
$mailer->Host = $agent['host'];
$mailer->Port = $agent['port'];
$mailer->Username = $agent['username']; // SMTP username
$mailer->Password = $agent['password']; // SMTP password
// setup different addresses
$mailer->From = $agent['from'];
$mailer->FromName = $agent['from_name'];
$mailer->addAddress($to, $name);
$mailer->addBCC($agent['bcc']);
$mailer->SingleTo = true;
// content
$mailer->Subject = $subject;
$mailer->Body = $html;
$mailer->AltBody = $text;
// finally, send out the mail message
if (!$mailer->Send()) {
throw new Exception('[Mailer] error: ' . $mailer->ErrorInfo);
}
// clear all addresses and attachments for next loop
$mailer->clearAddresses();