首页 > 解决方案 > PHPMailer 在点击提交按钮时将电子邮件发送到不同的地址和不同的正文

问题描述

  $autoemail = new PHPMailer\PHPMailer\PHPMailer();

  $autoemail->IsSMTP(); // send via SMTP

  $autoemail->CharSet="utf-8";

  $autoemail->WordWrap = 50; // set word wrap

  $autoemail->IsHTML(true); // send as HTML

  $autoemail->AddAddress("example@gmail.com"); 
  $autoemail->AddReplyTo("example@gmail","EXAMPLE"); 

  $autoemail->WordWrap = 50; 

$autoemail->Subject="Hello";    
$autoemail->Body="Testing only";

if(!$autoemail->Send())
    {
        echo "Message was not sent";
        echo "Mailer Error: " . $autoemail->ErrorInfo;
        exit;
    }

$autoemail->ClearAllRecipients();

$autoemail->AddAddress("pleasehelp@gmail.com", "EXAMPLE"); 

$autoemail->Body="Testing Only";

if(!$autoemail->Send())
    {
        echo "Message was not sent";
        echo "Mailer Error: " . $autoemail->ErrorInfo;
        exit;
    }

我想向两个不同的电子邮件地址发送电子邮件,但是这种编码给了我错误,它向两个地址发送了两次电子邮件,并且在发送电子邮件后,我的网页变成了白页,说它有错误 ERR_INCOMPLETE_CHUNKED_ENCODING。请帮我解决这个问题!谢谢!

标签: phpemailphpmailer

解决方案


您的代码看起来不错,但您可能有一个浏览器插件或导致多次提交的东西。如果您在主题行的末尾粘贴一个随机数,我希望您会发现每组消息它们会有所不同,这表明脚本多次运行,如下所示:

$autoemail->Subject="Hello".rand();    

查看您的访问日志也可能会显示多个请求。

分块编码错误似乎与此脚本无关。


推荐阅读