发送不同的电子邮件到不同的收件人php邮件

时间:2019-12-25 04:09:57

标签: php email

for($f=0; $f<count($person); $f++){

        $messageUser = "<div style='display: block; width: 520px; background-color: #edeeef; padding: 10px;'>
                        <p>Please confirm the payment voucher for<br>
                        <br>Request by: ".$usercreated."
                        <br>Voucher Name: ".$pv_name."
                        <br><br>Your pin no: <strong>".$pin[$f]."</strong>
                            <button>Confirm Account</button>
                        </a>
                        </div>
                        ";

        $headers .= "Reply-To: Nothing <admin@nothing.com>\r\n"; 
        $headers .= "Return-Path: Nothing <admin@nothing.com>\r\n"; 
        $headers .= "From: Nothing <admin@nothing.com>\r\n";  
        $headers .= "Bcc: Nothing <sales@nothing.com>\r\n"; 
        $headers .= "Organization: Nothing\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        //    $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
        $headers .= "Content-type: text/html\r\n";
        $headers .= "X-Priority: 3\r\n";
        $headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
        $from = "admin@nothing.com";

        $retvaladmin2 = mail($person[$f],$subject,$messageUser,$headers, "-f" . $from);
            if($retvaladmin2){
                $statusemail = 'success';
            }
echo $person[$f];
echo "<br>";
echo $statusemail;
echo "<br>";

}

我想发送验证码,该验证码是针对不同收件人的$ pin [$ f],每个收件人都有唯一的pin。我让它循环发送电子邮件。第一个收件人收到了电子邮件,但第二个收件人没有。它显示 554事务失败的错误:重复的标头'From'

1 个答案:

答案 0 :(得分:3)

您需要在循环迭代之间清除$headers