2011-10-10 70 views
2

我試圖使用CodeIgniter電子郵件類來編寫安全的SMTP電子郵件; SSL或TLS(首選)。在過去,我已經成功地將PHPMailer與Secure Auth和TLS結合使用。我相信這是一個安全的連接。 TLS顯示在電子郵件標題中。CodeIgniter:來自PHPMailer的SSL/TLS SMTP Auth電子郵件代碼

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 = '[email protected]'; 
$mail->Password = 'password'; 

$mail->From  = '[email protected]'; 
$mail->FromName = 'Alerts'; 

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

// To 
$mail->AddAddress('[email protected]', '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) "[email protected]" 
["smtp_pass"]=> string(9) "password" 
["smtp_to_email"]=> string(26) "[email protected]" 
["smtp_from_email"]=> string(26) "[email protected]" 
["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?

+1

您可以通過谷歌錯誤代碼來了解更多信息,或者只是在codeigniter中使用PHPMailer。您可以在CI的旁邊使用其他PHP庫,如果您已經有*正在工作的代碼*,這可能是一個好主意。 – hakre

+2

如果你有它在PHPMailer中工作,那麼我只是將它作爲一個庫在CI中。我以前親自在CI的電子郵件課上遇到了問題,並且做了同樣的事情。 – fire

回答

2

如何診斷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/[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代替。

+0

根據phpinfo() - 註冊流套接字傳輸:tcp,udp,unix,udg,ssl,sslv3,sslv2,tls。有沒有配置PHP使用SSLV3進行TLS連接的方法? – jjwdesign

+0

我認爲你不能正確理解這一點。但是,爲什麼你不使用PHPMailer類,你很好? – hakre