如何使用 PEAR Mail 工厂显式禁用 TLS?
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法是在 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
当前版本的 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.
改用 PHPMailer,并在 5 分钟内开始工作。
Switched to using PHPMailer instead and had it working in 5 minutes.