PHPMailer无法连接到服务器-设置正确



我正在使用PHPMailer在服务器上测试SMTP。SMTP服务器运行良好,在我的VBulletin论坛上,但在我自己的网站引擎上(从本地主机,但端口80是打开的,所以我通过我的ip进行),我得到以下错误:

2014-04-14 12:14:18 SMTP ERROR: Failed to connect to server:  SMTP connect() failed.

我问我的同事,他是服务器的经理,他说没有来自我的IP的连接。

我的PHPMailer设置:

public function create() {
    $mailer = new PHPMailer();
    $mailer->isSMTP();
    $mailer->CharSet = "UTF-8";
    $mailer->SMTPSecure = "tls";
    $mailer->host       = Config::$SMTP_HOST;
    $mailer->SMTPDebug  = 2;
    $mailer->SMTPAuth   = true;
    $mailer->Port       = Config::$SMTP_PORT;
    $mailer->Username   = Config::$SMTP_USER;
    $mailer->Password   = Config::$SMTP_PASS;
    return $mailer;
}
// SMTP details
public static $SMTP_PORT = 25;
public static $SMTP_HOST = "argonite.net";
public static $SMTP_USER = "recover@argonite.net";
public static $SMTP_PASS = "password";
public static $RECOVER_EMAIL = "recover@argonite.net";

这就是我使用它的方式:

            $mailer = (new MailFactory())->create();
            $mailer->addAddress($email, $username);
            $mailer->setFrom(Config::$RECOVER_EMAIL, "Recover");
            $mailer->Subject = "Password Recovery - DO NOT REPLY";
            $mailer->AltBody = "Argonite has sent you your password as requested.";
            $mailer->msgHTML($this->buildMessage($username, $this->getPassword($username, $email)));
            if (!$mailer->send()) {
                $fh = fopen("logs/.mailer", 'a');
                fwrite($fh, "n[" . date("Y-m-d H:i:s") . "]: " . $mailer->ErrorInfo . "n");
                fclose($fh);
                return "An error has occured while sending your request. Administrators have been notified.";
            }
            else {
                return "success";
            }

为什么会失败?这可能是我的PHPMailer设置、版本或Apache.php配置的问题吗?

php:5.5.9

修复-我真的不知道怎么做,但这是我设置的设置:

    $mailer->SMTPSecure = "none";
    $mailer->host       = Config::$SMTP_HOST;
    $mailer->SMTPDebug  = 0;
    $mailer->SMTPAuth   = false;
    $mailer->Port       = Config::$SMTP_PORT;
    $mailer->Username   = Config::$SMTP_USER;
    $mailer->Password   = Config::$SMTP_PASS;

在添加了secure="none"和auth=false以及端口25之后,它就工作了。

相关内容

  • 没有找到相关文章

最新更新