doucheng5209 2018-05-22 19:52
浏览 82
已采纳

新的PHPMailer没有运行?

Below is the phpmailer code which I am using :

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    require '../vendor/autoload.php'; 
    $mail = new PHPMailer(true);  
    try { 
     $mail->SMTPDebug = 2; 
     $mail->isSMTP();
     $mail->Host = as given in the configure mail client window; 
     $mail->SMTPAuth = true; 
     $mail->Username =as given in the configure mail client window; 
     $mail->Password = as given in the configure mail client window;  
     $mail->SMTPSecure = 'tls' ;
     $mail->Port = 465; 
     $mail->setFrom('my email', 'my name'); 
     $mail->addAddress('email', 'name');
     $mail->isHTML(true);
     $mail->Subject = 'Here is the subject';
     $mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
     $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
     $mail->send(); 
    echo 'Message has been sent';
     } 

    catch (Exception $e) { 
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
     }

The page keeps loading and the e-mail is not sent,What is happening ? and how should I configure this . I am using godaddy cpanel.

  • 写回答

1条回答 默认 最新

  • douyang5943 2018-05-22 20:15
    关注

    You're using SMTP to localhost (which is the recommended and usually the fastest sending mechanism, as far as your script is concerned), but you've enabled encryption and authentication, so your local mail server will need to present a valid certificate for localhost, which is not going to happen. It's usually unnecessary to use encryption or authentication when sending to localhost, because you can whitelist localhost as the source, and this will make it even faster.

    If you set SMTPDebug = 2, you can look at the timestamps in the SMTP conversation and see which part is taking a long time.

    Keepalive won't help unless you're sending lots of messages in quick succession.

    It may also help to look in your local mail server's logs and see if there's anything interesting in there.

    You're also using a very old version of PHPMailer; get the latest, and base your code on the examples provided.

    You should have no trouble submitting a few hundred messages per second.

    If your problem is that submission is fast, but ultimate delivery is slow, you need to look at your local mail server logs for why that is. You may be getting delivery deferrals.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥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之后自动重连失效