使用Bluehost对PHPMailer进行故障排除

时间:2018-11-27 07:13:57

标签: php smtp phpmailer

尝试为我在Bluehost上托管的网站设置PHPMailer,经过一整天的研究和故障排除后,我仍然无法正常工作。

我是一个初学者,所以对于新手问题要提前道歉,但是我一直在阅读我能找到的所有内容(包括thisthis以及PHPMailer docs )解决此问题,但似乎无法正确设置我的设置。任何指导,对我正在做的事情的想法或调试方法的想法都将受到赞赏。

这是我关于Bluehost SMTP的发现。

  

安全的SSL / TLS设置(推荐)

  用户名您的电子邮件地址:john@example.com
  密码该电子邮件帐户的密码。
  传入服务器mail.example.com *
  传入端口993(IMAP)或995(POP3)
  寄出伺服器mail.example.com *
  传出端口465(SMTP)
  身份验证密码

   *用您的域名替换example.com。

以下是我在文件中使用的内容(已删除个人信息)。

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

$mail = new PHPMailer(true);     
try {
    //Server settings
    $mail->SMTPDebug = 2;             
    $mail->isSMTP();                  
    $mail->Host = 'mail.MYDOMAIN.com';  
    $mail->SMTPAuth = true;            
    $mail->Username = 'MYEMAIL@MYDOMAIN.com';   
    $mail->Password = 'MYEMAILPASSWORD';        
    $mail->SMTPSecure = 'tls';                  
    $mail->Port = 465;                          

    //Recipients
    $mail->setFrom('MYEMAIL@MYDOMAIN.com');
    $mail->addAddress('MYEMAIL@MYDOMAIN.com'); 

    //Content
    $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;
}

我已经使用Composer安装了PHPMailer,因此autoload.php文件(和phpmailer文件夹)位于与该文件所在目录相同的目录下的“ vendor”文件夹中。

上传到我的Bluehost服务器后,当我尝试在浏览器中显示包含此代码的网页时,我得到了HTTP ERROR 500屏幕截图,当然也没有发送电子邮件。

Error screen shot

1 个答案:

答案 0 :(得分:0)

许多示例和the docs中涉及的内容是加密和端口设置的组合将起作用的方式。

您有Port = 465SMTPSecure = 'tls';那行不通。可以将Port更改为587,或将SMTPSecure更改为'ssl'(但不能同时使用 !)。就目前情况而言,您正在尝试使用期望使用STARTTLS对其进行显式显示的协议来打开与期望隐式TLS的端口的连接,而这将无法正常工作。

相关问题