如何使用 PEAR Mail 工厂显式禁用 TLS?

发布于 2024-09-27 11:55:53 字数 1432 浏览 6 评论 0原文

使用 PHP,我尝试通过 AuthSMTP(托管 SMTP 服务)路由电子邮件。问题是 PEAR 邮件工厂自动尝试与服务器协商 TLS 连接。 AuthSMTP 不会简单地忽略该尝试,而是会引发错误。我需要一种方法来明确告诉 Mailer 类不要尝试使用 TLS。有什么建议吗?

    $from = "Example <[email protected]>";
    $to = $email;
    $subject = "This is an email";

    $body_text = "plain text here";
    $body_html = "<h1>HTML here!</h1>";

    $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);

    $mime = new Mail_mime('rn');
    $mime->setTXTBody($body_text);
    $mime->setHTMLBody($body_html);

    $body = $mime->get();
    $hdrs = $mime->headers($headers);

    $host = "mail.authsmtp.com";
    $port = 26;
    $username = "my_username";
    $password = "whatever_password";

    $mailer = Mail::factory('smtp',
    array ('host' => $host,
     'auth' => true,
     'port' => $port,
     'username' => $username,
     'password' => $password));

    if (PEAR::isError($res)) {
        throw new Exception($res->getMessage());
    } else {
        return true;
    } 

AuthSMTP 给我以下错误:

SMTP: Invalid response code received from server (code: 428, response: 4.0.0 Your account is using SSL - either disable it in your email client or enable it at http://control.authsmtp.com)

Using PHP, I'm attempting to route email through AuthSMTP (a hosted SMTP service). The problem is that the PEAR mail factory automatically tries to negotiation a TLS connection with the server. Rather than simply ignoring the attempt, AuthSMTP throws an error. I need a way to explicitly tell the Mailer class not to try to use TLS. Any suggestions?

    $from = "Example <[email protected]>";
    $to = $email;
    $subject = "This is an email";

    $body_text = "plain text here";
    $body_html = "<h1>HTML here!</h1>";

    $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);

    $mime = new Mail_mime('rn');
    $mime->setTXTBody($body_text);
    $mime->setHTMLBody($body_html);

    $body = $mime->get();
    $hdrs = $mime->headers($headers);

    $host = "mail.authsmtp.com";
    $port = 26;
    $username = "my_username";
    $password = "whatever_password";

    $mailer = Mail::factory('smtp',
    array ('host' => $host,
     'auth' => true,
     'port' => $port,
     'username' => $username,
     'password' => $password));

    if (PEAR::isError($res)) {
        throw new Exception($res->getMessage());
    } else {
        return true;
    } 

AuthSMTP is giving me the following error:

SMTP: Invalid response code received from server (code: 428, response: 4.0.0 Your account is using SSL - either disable it in your email client or enable it at http://control.authsmtp.com)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江心雾 2024-10-04 11:55:54

最简单的方法是在 PEAR\NET\SMTP.php 中函数 auth 的定义中将 $tls=true 更改为 $tls=false

The easiest way is to change $tls=true to $tls=false in the definition of the function auth in PEAR\NET\SMTP.php

心清如水 2024-10-04 11:55:54

当前版本的 PEAR Mail 软件包无法完成此操作 - 但 是请求的功能。我已经上传了一个补丁,以便可以完成此操作。希望新版本很快就会发布。

This can't be done with a current release of the PEAR Mail package - but is a requested feature. I've uploaded a patch so that this can be done. Hopefully a new release will be distributed soon.

jJeQQOZ5 2024-10-04 11:55:54

改用 PHPMailer,并在 5 分钟内开始工作。

Switched to using PHPMailer instead and had it working in 5 minutes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文