[英]PHPMailer - Sending multiple emails to addresses stored in the mySQL database
I have the following snippet where I'm trying to send e-mails to multiple addresses.我有以下代码段,我试图将电子邮件发送到多个地址。
$recipients = array();
while ($row = mysqli_fetch_array($result)){
$recipients[] = $row;
}
$recipients = array(
'user_1@domain.com' => 'user_1_name',
'user_2@domain.com' => 'user_2_name',
);
foreach($recipients as $email => $name)
{
$mail->addAddress($email, $name);
}
I need to get the email addresses array dynamically filled with the content from the database and tried this.我需要使用数据库中的内容动态填充电子邮件地址数组并尝试这样做。
$recipients[] = array(
$row1['email'] => $row1['name']
);
I'm getting the following error so I know I haven't got the array correctly.我收到以下错误,所以我知道我没有正确获得数组。 Appreciate your thoughts on what have I got wrong in there.感谢您对我在那里做错了什么的想法。
Warning: trim() expects parameter 1 to be string, array given in /Applications/XAMPP...警告:trim() 期望参数 1 是字符串,数组在 /Applications/XAMPP...
EDIT编辑
PHPMailer also triggers the below error, which I understand since the array I'm trying to dynamically populate isn't getting any of the email addresses from the database. PHPMailer 还会触发以下错误,我理解这是因为我尝试动态填充的数组没有从数据库中获取任何电子邮件地址。
Mailer Error: You must provide at least one recipient email address.邮件错误:您必须至少提供一个收件人电子邮件地址。
You can directly get address可以直接获取地址
$recipients = array();
while ($row = mysqli_fetch_array($result)){
$mail->addRecipent($row['email'], $row['name']);
}
ps better use for
ps 更好地for
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.