简体   繁体   English

CodeIgniter:来自PHPMailer代码的SSL / TLS SMTP身份验证电子邮件

[英]CodeIgniter: SSL/TLS SMTP Auth Email from PHPMailer Code

I'm trying to use the CodeIgniter Email Class to write a secure SMTP email; 我正在尝试使用CodeIgniter电子邮件类编写安全的SMTP电子邮件。 either SSL or TLS (preferred). SSL或TLS(首选)。 In the past, I've successfully used PHPMailer with Secure Auth and TLS. 过去,我已经成功将PHPMailer与Secure Auth和TLS结合使用。 I believe it was a secure connection. 我相信这是一个安全的连接。 TLS shows up in the email header. TLS显示在电子邮件标题中。

Does CodeIngiters' Email Class support secure SMTP authentication with TLS? CodeIngiters的电子邮件类别是否支持带TLS的安全SMTP身份验证?

Note, this is not a Gmail question. 请注意,这不是Gmail问题。 I'm trying to use it with an MS Exchange Server. 我正在尝试将其与MS Exchange Server一起使用。 I've confirmed the PHPMailer code below functions correctly. 我已经确认下面的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();

With CodeIgniter I've already extended the Email Class (MY_Email.php). 使用CodeIgniter,我已经扩展了电子邮件类(MY_Email.php)。 The class is a bit big to post here. 这个班有点大,可以在这里发布。 But, here's the error I keep getting. 但是,这是我不断得到的错误。

Settings: 设置:

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" 
}

Error Message: 错误信息:

fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:func(143):reason(267) fsockopen():SSL操作失败,代码为1。OpenSSL错误消息:错误:1408F10B:SSL例程:func(143):原因(267)

Any idea what reason 267 is? 知道267是什么原因吗?

How to diagnose OpenSSL errors: 如何诊断OpenSSL错误:

Look at the error message: 查看错误消息:

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

Take the reason code (267) and determine the error: 获取原因码(267)并确定错误:

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

Now google for SSL_R_WRONG_VERSION_NUMBER 现在在Google SSL_R_WRONG_VERSION_NUMBER

Read the first hit: http://www.mail-archive.com/openssl-dev@openssl.org/msg02770.html 阅读第一篇文章: 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.
"

Conclusion: the smtp-server uses SSLv3_server_method and therefore needs to be fixed to use SSLv23 instead. 结论:smtp服务器使用SSLv3_server_method,因此需要修复以使用SSLv23。

Found a solution on the CI forums. 在CI论坛上找到了解决方案。

Exchange Email Class Patch http://codeigniter.com/forums/viewthread/158882/ Exchange电子邮件类补丁程序http://codeigniter.com/forums/viewthread/158882/

It is initiating TLS after SMTP server has been connected. 连接SMTP服务器后,它将启动TLS。

Worked for me. 为我工作。 Jeff 杰夫

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM