【问题标题】:How do i send mails to multiple recipients如何将邮件发送给多个收件人
【发布时间】:2017-09-26 09:00:55
【问题描述】:

我正在尝试使用数据库来模拟电子邮件行为。这些是我用于向一位收件人发送邮件的代码。如何将其发送给多个收件人。

    if($to=="" || $sub=="" || $msg=="")
    {
        $err= "<h3 style='color:red'>fill the related data first</h3>";
    }
    else
    {   
        $d=mysqli_query($con,"SELECT * FROM userinfo where email='$to'");
        $row=mysqli_num_rows($d);
        if($row==1)
        {
            mysqli_query($con,"INSERT INTO usermail values('','$to','$id','$sub','$msg','$file',sysdate())");

            $err= "<h3 style='color:blue'>Message sent...</h3>";
        }
        else
        {
            $sub=$sub."--"."msg failed";
            mysqli_query($con,"INSERT INTO usermail values('','$id','$id','$sub','$msg','$file',sysdate())");
            $err= "<h3 style='color:red'>Message failed because reciever not found...</h3>";
        }   
    }

【问题讨论】:

  • 此代码中的任何内容都不会发送电子邮件。
  • @FrankerZ 哈哈。也许其他一些进程会定期检查usermail 表...?
  • 用你的问题和代码澄清。在代码中添加 cmets。
  • 如果您使用的是mail(),那么您可以用逗号分隔收件人列表:johny@example.com, sally@example.com

标签: php


【解决方案1】:

如果我遇到了你的问题:

假设$to="abc@x.com;zdf@x.com";

else
{ 
   $toStack = explode(';',$to);
   foreach($toStack as $to){
     $d=mysqli_query($con,"SELECT * FROM userinfo where email='$to'");
     /** and the rest of your code from the else block **/
   }
}

祝你有美好的一天..

【讨论】:

    猜你喜欢
    • 2014-02-06
    • 1970-01-01
    • 2018-11-19
    • 2013-09-02
    • 1970-01-01
    • 2021-06-27
    • 2019-06-17
    • 2016-08-21
    • 1970-01-01
    相关资源
    最近更新 更多