Linux環境下使用PHPmailer發送郵件時,出現如下錯誤:
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (32690)
出現這個問題的原因是當初編譯安裝PHP缺少了ssl庫。
可以重新再次編譯PHP,加上--enable-openssl參數即可。
但是如果只為了安裝這一個擴展就去重新編譯,未免有點麻煩,其實可以簡單一點,只要安裝openssl.so擴展就可以了。
(1)找到之前編譯安裝PHP的安裝包,或者從php的官網下載php7(本例使用php7,其他版本的PHP類似)
(2)解壓並進入文件夾
cd php7.0/ext/openssl
(3)運行 phpize:
/usr/local/php/bin/phpize
備注,如果出現如下錯誤:Cannot find config.m4.
Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module
【解決辦法】cp ./config0.m4 ./config.m4 即可解決
(4)編譯和安裝
./configure --with-openssl --with-php-config=/usr/local/php/bin/php-config make && make install
(5)然后進入最后提示的目錄,查看文件如下:
(6)將 openssl.so 復制到PHP的擴展目錄下:
cp openssl.so /usr/local/php/include/php/ext
(7)找到php.ini,在最后面添加如下內容:
extension=openssl.so
(8)重啟php-fpm和nginx/apache,查看phpinfo();