【问题标题】:CodeIgniter: SSL/TLS SMTP Auth Email from PHPMailer CodeCodeIgniter:来自 PHPMailer 代码的 SSL/TLS SMTP Auth 电子邮件
【发布时间】:2011-12-04 13:11:23
【问题描述】:

我正在尝试使用 CodeIgniter 电子邮件类来编写安全的 SMTP 电子邮件; SSL 或 TLS(首选)。过去,我已经成功地将 PHPMailer 与 Secure Auth 和 TLS 一起使用。我相信这是一个安全的连接。 TLS 显示在电子邮件标题中。

CodeIngiters 的电子邮件类是否支持使用 TLS 的安全 SMTP 身份验证?

请注意,这不是 Gmail 问题。我正在尝试将它与 MS Exchange Server 一起使用。我已经确认下面的 PHPMailer 代码功能正确。

include_once('includes/class.phpmailer.php');
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->Host = 'www.domain.com';

$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port     = '25';
$mail->Timeout  = '60';

$mail->Username = 'user@domain.com';
$mail->Password = 'password';

$mail->From     = 'alerts@domain.com';
$mail->FromName = 'Alerts';

$mail->Subject  = 'Test from test email file.';
$mail->IsHTML(true);
$mail->MsgHTML('This is just a test.');

// To
$mail->AddAddress('alerts@domain.com', 'Research');
$result = $mail->Send();

使用 CodeIgniter,我已经扩展了电子邮件类 (MY_Email.php)。这个类有点大,可以在这里发布。但是,这是我不断遇到的错误。

设置:

array(7) { 
["smtp_host"]=> string(26) "tls://www.domain.com" 
["smtp_port"]=> string(2) "25" 
["smtp_user"]=> string(17) "alerts@domain.com" 
["smtp_pass"]=> string(9) "password" 
["smtp_to_email"]=> string(26) "user@domain.com" 
["smtp_from_email"]=> string(26) "user@domain.com" 
["smtp_from_name"]=> string(24) "Test from Application" 
}

错误信息:

fsockopen():SSL 操作失败,代码为 1。OpenSSL 错误消息:error:1408F10B:SSLroutines:func(143):reason(267)

知道 267 是什么原因吗?

【问题讨论】:

  • 您可以通过谷歌搜索错误代码以了解更多信息,或者仅在 codeigniter 中使用 PHPMailer。您可以使用 CI 旁边的其他 PHP 库,如果您已经拥有 正在运行的代码,这可能是个好主意。
  • 如果你让它在 PHPMailer 中工作,那么我会把它作为一个库包含在 CI 中。我个人过去曾在 CI 的电子邮件课程上遇到过问题,并且也做过同样的事情。

标签: php codeigniter email smtp


【解决方案1】:

如何诊断 OpenSSL 错误:

查看错误信息:

error:1408F10B:SSL routines:func(143):reason(267)

取原因码(267)并判断错误:

grep 267 /usr/include/openssl/ssl.h
/usr/include/openssl/ssl.h:#define SSL_R_WRONG_VERSION_NUMBER                    267

现在用谷歌搜索SSL_R_WRONG_VERSION_NUMBER

阅读第一个命中: http://www.mail-archive.com/openssl-dev@openssl.org/msg02770.html

"
    Many of SSL clients sends the first CLIENT HELLO with
    ssl2 format (0x80.....) because they don't know what
    version the server supports.
    In this first message, the client sends the version
    he wants to use (3 for SSL3), then the other exchanged
    messages are in the appropriate format SSL3 for V3,
    SSL2 for V2 etc....

    So in your server method configuration you must put:
      SSL_CTX *ctx = SSL_CTX_new (SSLv23_server_method())
    to correctely analyse the first client_hello message
    instead of 
      SSL_CTX *ctx = SSL_CTX_new (SSLv3_server_method())
    which i suppose you did.
"

结论:smtp-server 使用 SSLv3_server_method,因此需要修正为使用 SSLv23。

【讨论】:

  • 根据 phpinfo() - 注册的流套接字传输:tcp、udp、unix、udg、ssl、sslv3、sslv2、tls。有没有办法将 PHP 配置为使用 SSLV3 进行 TLS 连接?
  • 我认为您没有正确理解这一点。但是,为什么不直接使用 PHPMailer 类就可以了?
【解决方案2】:

在 CI 论坛上找到了解决方案。

Exchange 电子邮件类补丁 http://codeigniter.com/forums/viewthread/158882/

它正在启动 TLS SMTP 服务器已连接。

为我工作。杰夫

【讨论】:

  • 升级到 CodeIgniter V3。
猜你喜欢
  • 1970-01-01
  • 2014-10-19
  • 2016-06-25
  • 2014-06-07
  • 2019-07-06
  • 2020-07-31
  • 2012-12-31
  • 1970-01-01
  • 2014-06-23
相关资源
最近更新 更多