在标题中,我无法向多个收件人发送电子邮件,因为我检索到以下错误:
无法发送消息。邮件程序错误:您必须至少提供一个收件人电子邮件地址。
我正在使用此代码:
$stmt=$db->prepare("select email from app_users where enabled=1");
if (!$stmt) {
log_msg($db->error);
die();
}
if (!test_execute($stmt->execute())) die("ERROR");
$emailto=fetchArray2($stmt);
$stmt->close();
foreach ($emailto as $contacts) {
$mail->AddAddress($contacts);
}
出了什么问题?
的print_r($ emailto);
Array
(
[0] => Array
(
[email] => recipient1@hotmail.com
)
[1] => Array
(
[email] => recipient2@gmail.com
)
[2] => Array
(
[email] => recipient3@yahoo.com
)
)
答案 0 :(得分:1)
foreach ($emailto as $contacts) {
$mail->addAddress($contacts['email']);
}
检查返回值也是个好主意,可能是:
foreach ($emailto as $contacts) {
if (!$mail->addAddress($contacts['email'])) {
echo 'Address rejected: '.$contacts['email'];
}
}