doufei1893 2018-03-17 08:35
浏览 120
已采纳

在CC中发送两个电子邮件ID

I am obtaining two email id's from database by a query. Both stored in a single variable. I want to send email to these two addresses by PHPMailer keeping them in cc. Currently only one email is being selected and passed in cc. Can I know where am I going wrong. My code here,

  $get_cc_email_id_sql=mysql_query("select * from tbl_name where column_name IN(13,5)");
          $user_email_cc='';
          while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
          {

           $user_email_cc=$get_data_cc['email'];

          } 
$mail = new PHPMailer();
$subject = "Mail";  
$content ="XYZ";
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Debugoutput = 'html';
$mail->Port     = 465;  
$mail->Username = "xyz@xyz.com";   // Changed username and password from 
$mail->Password = "xyz";
$mail->Host     = "ssl://smtp.xyz.com";
$mail->Mailer   = "smtp";
$mail->SetFrom("xyz@xyz.com", "XYZ");
$mail->AddAddress(abc@abc.com);
$mail->AddCC($user_email_cc);
$mail->Subject = $subject;
$mail->WordWrap   = 80;
$mail->MsgHTML($content);
$mail->IsHTML(true);  
if(!$mail->Send()) 
    echo "Problem sending mail.";   
else      
  echo "Mail Sent"; 
  • 写回答

3条回答 默认 最新

  • douhuang3833 2018-03-17 08:40
    关注

    use $user_email_cc as array then it will store you both email a 0 and 1 position

    $user_email_cc=array();
              while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
              {
    
               $user_email_cc[] =$get_data_cc['email'];
    
              } 
    

    New Code

    $get_cc_email_id_sql=mysql_query("select * from tbl_name where column_name IN(13,5)");
             $user_email_cc=array();
              while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
              {
    
               $user_email_cc[] =$get_data_cc['email'];
    
              } 
    $mail = new PHPMailer();
    $subject = "Mail";  
    $content ="XYZ";
    $mail->IsSMTP();
    $mail->SMTPDebug = 0;
    $mail->SMTPAuth = TRUE;
    $mail->SMTPSecure = "ssl";
    $mail->Debugoutput = 'html';
    $mail->Port     = 465;  
    $mail->Username = "xyz@xyz.com";   // Changed username and password from 
    $mail->Password = "xyz";
    $mail->Host     = "ssl://smtp.xyz.com";
    $mail->Mailer   = "smtp";
    $mail->SetFrom("xyz@xyz.com", "XYZ");
    foreach($user_email_cc as $email_cc){
     $mail->AddCC($email_cc);
    }
    $mail->AddAddress(abc@abc.com);
    $mail->Subject = $subject;
    $mail->WordWrap   = 80;
    $mail->MsgHTML($content);
    $mail->IsHTML(true);  
    if(!$mail->Send()) 
        echo "Problem sending mail.";   
    else      
      echo "Mail Sent"; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口