如何使用phpmailer添加多个cc电子邮件地址
我正在尝试在phpmailer AddCC中添加多个电子邮件地址 使用下面的代码,我只能在cc中添加一个电子邮件地址。但是我想添加从查询中获取的所有电子邮件如何使用phpmailer添加多个cc电子邮件地址,php,email,phpmailer,Php,Email,Phpmailer,我正在尝试在phpmailer AddCC中添加多个电子邮件地址 使用下面的代码,我只能在cc中添加一个电子邮件地址。但是我想添加从查询中获取的所有电子邮件 $sqlcc = "SELECT * FROM notificationslist WHERE status='1'"; $querycc = $connect->query($sqlcc); $num_rowscc = mysqli_num_rows($querycc); if($num_rowscc>0){
$sqlcc = "SELECT * FROM notificationslist WHERE status='1'";
$querycc = $connect->query($sqlcc);
$num_rowscc = mysqli_num_rows($querycc);
if($num_rowscc>0){
while ($row = $querycc->fetch_assoc()) {
$ccemail= $row['email'];
$ccname= $row['employee'];
}
} else {
$ccemail= 'akash1sethi@gmail.com';
$ccname= 'Akash Sethi';
}
PHP邮件程序代码
创建一个数组以存储多封抄送电子邮件
while ($row = $querycc->fetch_assoc()) {
$ccemail[]= $row['email'];
$ccname[]= $row['employee'];
}
这些数组都是phpmailer代码
或者您可以使用下面的代码
if($num_rowscc>0){
while ($row = $querycc->fetch_assoc()) {
// create an array to have multiple records
$recipients[]= array('email'=>$row['email'],'name'=>$row['employee']);
}
} else {
$recipients[]= array('email'=>'akash1sethi@gmail.com','name'=>'Akash Sethi');
}
在phpmailer中
// loop the array and add to cc
foreach($recipients as $recipient){
$mail->AddCC($recipient['email'],$recipient['name']);
}
您的方法有效,您确定添加的值正确吗?您要添加多少?@rtfm在while循环中,他没有创建数组,而是直接给变量赋值,而变量只会有最后的结果。
// loop the array and add to cc
foreach($recipients as $recipient){
$mail->AddCC($recipient['email'],$recipient['name']);
}