doumeng1089 2012-03-28 13:42
浏览 35
已采纳

从数据库获取列表电子邮件列表,并从PHP脚本发送邮件,而不使用任何API

 $sql = "select emailid from table where category = 1";
    while($row=mysql_fetch_array($sql))
    {
            $email=$row['emailid'];
            $to = $email;

            $subject = "E-mail subject";
            $body = "E-mail body";
            $headers = 'From: info@mydomain.com' . "
" ;
            $headers .= 'Reply-To: info@mydomain.com' . "
";
            mail($to, $subject, $body, $headers);
    }

Suppose the above code will fetch 100 e-mail ids from database and send the mail one by one to each e-mail id. but what i want to do is.... fetch all e-mail ids in an array and send them as 'BCC' to each e-mail at once. one more thing i want to customize the e-mail body content for each id....

Any ideas?

  • 写回答

1条回答 默认 最新

  • dpcj40970 2012-03-28 13:47
    关注

    What you want to do is impossible. If you send them at once via multiple addresses in To/CC/BCC, everyone gets exactly the same email. So you cannot customize the bodies.

    If sending the same email to everyone is fine, try this:

    $sql = mysql_query("select emailid from table where category = 1");
    $recipients = array();
    while($row = mysql_fetch_array($sql)) {
        $recipients[] = $row['emailid'];
    }
    
    $to = 'info@mydomain.com';
    $subject = "E-mail subject";
    $body = "E-mail body";
    $headers = 'From: info@mydomain.com' . "
    " ;
    $headers .= 'Reply-To: info@mydomain.com' . "
    ";
    $headers .= 'BCC: ' . implode(', ', $recipients) . "
    ";
    
    mail($to, $subject, $body, $headers);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突