dtl85148 2016-09-27 10:57
浏览 70

PhPMailer - 您必须提供至少一个收件人电子邮件地址 - 但无论如何都要发送邮件

I've got a PHPMailer setup which works fine, but when I added BCC it begins to report error. I can't see what exactly causing this issue.

I've got this error report: You must provide at least one recipient email address.

The strange thing is, that it's sending the emails correctly to both recipients but never changes to my 'succes.php'-page. It just simply showing the error reporting.

I have tried almost any combination of ADD and Clear, but keep getting somekind of issue. What I'm facing now, does sends the emails, but still reporting error.

My setup is like this:

    try {
        // Ens for all
        $mail->Host       = 'localhost'; // SMTP server
        $mail->AddReplyTo('no-reply@XXX.dk', 'XXX Mailer');
        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; 
        $mail->AddAddress("$email");
        $mail->AddBCC("$bcc");
        $mail->Subject = "$subject";
        $mail->MsgHTML($message);
        $mail->Send();
        $mail->ClearBCCs();
        $mail->ClearAddresses();
        if(!$mail->Send()) {
            header('Location: fejl.php');
        } else { 
            header('Location: succes.php');
        }

    } catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
      echo $e->getMessage(); //Boring error messages from anything else!
    }
} // end of if !mail

else { //report the errors
    echo 'TEST ERRORS';
    foreach ($errors as $msg) { //prints each error
        echo " - $msg<br />
";;
    } // end of foreach
    echo 'End';
} //end of if(empty($errors)) 
  • 写回答

1条回答 默认 最新

  • duanben4771 2016-09-27 12:57
    关注

    Basic error:

        $mail->Send();
        $mail->ClearBCCs();
        $mail->ClearAddresses();
        if(!$mail->Send()) {
    

    You're calling send(), removing all the addresses, then calling send() again, hence the error.

    You've also based your code on an old, obsolete example, so you're probably running an old version of PHPMailer. Get the latest.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改