Php 如何向多个收件人发送邮件

Php 如何向多个收件人发送邮件,php,Php,我正在尝试使用数据库模拟电子邮件行为。这些是我用来向一个收件人发送邮件的代码。如何将其发送给多个收件人 if($to=="" || $sub=="" || $msg=="") { $err= "<h3 style='color:red'>fill the related data first</h3>"; } else { $d=mysqli_query($con,"SELECT * FROM

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

    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>";
        }   
    }
if($to==“”| |$sub==“”| |$msg==“”)
{
$err=“先填写相关数据”;
}
其他的
{   
$d=mysqli_查询($con,“从userinfo中选择*,其中email='$to');
$row=mysqli\u num\u行($d);
如果($row==1)
{
mysqli_query($con,“插入到用户邮件值('''$to','$id','$sub','$msg','$file',sysdate())”);
$err=“已发送消息…”;
}
其他的
{
$sub=$sub.“--”消息失败;
mysqli_query($con,“插入到用户邮件值('''$id','$id','$sub','$msg','$file',sysdate())”);
$err=“消息失败,因为找不到接收者…”;
}   
}
如果我发现了你的问题:

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


祝你度过愉快的一天。

这段代码中没有任何内容会发送电子邮件。@FrankerZ-haha。也许其他流程会定期检查
usermail
表…?请澄清您的问题和代码。在代码中添加注释。如果使用,则可以用逗号分隔收件人列表:
johny@example.com, sally@example.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 **/
   }
}