簡體   English   中英

如何使用phpmailer添加多個抄送電子郵件地址

[英]How to add multiple cc email address using phpmailer

我正在嘗試在phpmailer AddCC()中添加多個電子郵件地址。

使用以下代碼,我只能在抄送中添加一個電子郵件地址。 但我想添加從查詢中獲取的所有電子郵件。

$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 MAILER代碼在這里

$multiplecc = array(
    $ccemail => $ccname,
    );


foreach ($multiplecc as $ccemail => $ccname)
{
    $mail->AddCC(trim($ccemail), $ccname);
}

創建一個數組來存儲多個抄送電子郵件。

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']);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM