phpmailer本身是一個很不錯的開源郵件類,也非常的易用簡單,就是偶爾會出現(xiàn)程序上傳到服務(wù)器上不能發(fā)送郵件的情況,在之前也有同學(xué)問過我這個問題,當(dāng)時的時候總是不以為然,今天終于讓我碰上了,用phpmailer 在本地測試正常,上傳到服務(wù)器上就不行了,當(dāng)然了是用的SMTP方式,最終確定是fsockopen 函數(shù)惹的禍,因為安全原因fsockopen 和pfsockopen 經(jīng)常被服務(wù)器端關(guān)閉。解決方法如下:
而代之的應(yīng)該是 stream_socket_client()函數(shù),不過他的參數(shù)有一點不一樣。
應(yīng)這樣更改phpmailer 的 class.stmp.php文件:
1
2
3
4
5
|
$this ->smtp_conn = @ fsockopen ( $host , // the host of the server $port , // the port to use $errno , // error number if any $errstr , // error message if any $tval ); // give up after ? secs |
改為
1
2
3
4
|
$this ->smtp_conn = @stream_socket_client( $host . ':' . $port , // the host of the server $errno , // error number if any $errstr , // error message if any $tval ); // give up after ? secs |
這里 PHP版本應(yīng)高于 5.0 的,因為較早版本沒有stream_socket_client()函數(shù)的。
OK ,問題解決了。