我正在尝试使用 CodeIgniter 电子邮件类来编写安全的 SMTP 电子邮件; SSL 或 TLS(首选)。过去,我成功地使用了具有安全身份验证和 TLS 的 PHPMailer。我相信这是一个安全的连接。 TLS 显示在电子邮件 header 中。
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 = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7d2d4c2d5e7c3c8cac6cec989c4c8ca" rel="noreferrer noopener nofollow">[email protected]</a>';
$mail->Password = 'password';
$mail->From = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2445484156505764404b49454d4a0a474b49" rel="noreferrer noopener nofollow">[email protected]</a>';
$mail->FromName = 'Alerts';
$mail->Subject = 'Test from test email file.';
$mail->IsHTML(true);
$mail->MsgHTML('This is just a test.');
// To
$mail->AddAddress('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="21404d4453555261454e4c40484f0f424e4c" rel="noreferrer noopener nofollow">[email protected]</a>', 'Research');
$result = $mail->Send();
通过 CodeIgniter,我已经扩展了电子邮件类 (MY_Email.php)。类(class)有点大,无法在这里发布。但是,这是我不断收到的错误。
设置:
array(7) {
["smtp_host"]=> string(26) "tls://www.domain.com"
["smtp_port"]=> string(2) "25"
["smtp_user"]=> string(17) "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b5a575e494f487b5f54565a525515585456" rel="noreferrer noopener nofollow">[email protected]</a>"
["smtp_pass"]=> string(9) "password"
["smtp_to_email"]=> string(26) "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="46333523340622292b272f286825292b" rel="noreferrer noopener nofollow">[email protected]</a>"
["smtp_from_email"]=> string(26) "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f98c8a9c8bb99d9694989097d79a9694" rel="noreferrer noopener nofollow">[email protected]</a>"
["smtp_from_name"]=> string(24) "Test from Application"
}
错误消息:
fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:func(143):reason(267)
知道 267 是什么原因吗?
最佳答案
如何诊断 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
现在在 Google 上搜索 SSL_R_WRONG_VERSION_NUMBER
阅读第一个命中: http://www.mail-archive.com/[email protected]/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 服务器使用 SSLv3_server_method,因此需要修复以使用 SSLv23。
关于php - CodeIgniter:来自 PHPMailer 代码的 SSL/TLS SMTP 身份验证电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7713701/