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 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应