php、gmail、swiftmailer を使用して電子メールを送信すると、SSL 関連のエラーが発生する
-
27-10-2019 - |
質問
私のPHPコードは次のとおりです。
function SendCookieToTheMail()
{
require_once 'swift-mailer/lib/swift_required.php';
//Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
->setPort(465)
->setEncryption('ssl')
->setUsername('007@gmail.com')
->setPassword('123')
;
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Create a message
$message = Swift_Message::newInstance('Test')
->setFrom(array('007@gmail.com' => 'From mr. 007'))
->setTo(array('007@gmail.com', '007@gmail.com' => 'To mr. 007'))
->setBody('Body')
;
//Send the message
$result = $mailer->send($message);
/*
You can alternatively use batchSend() to send the message
$result = $mailer->batchSend($message);
*/
}
エラーは次のとおりです。
( ! ) Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:\Program Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.php on line 233
( ! ) Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? #44551400]' in C:\Program Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.php on line 235
( ! ) Swift_TransportException: Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? #44551400] in C:\Program Files\wamp\www\swift-mailer\lib\classes\Swift\Transport\StreamBuffer.php on line 235
問題はどこだ??
アップデート:
私がチェックしました phpinfo()
そしてそれはこう言います:
OpenSSL support disabled (install ext/openssl)
以下のリンクを参考にしたのですが、SSLがインストールできませんでした…。
解決
PHP は SSL をサポートしていましたか? http://php.net/manual/en/function.fsockopen.php, 、チェックしてください http://www.php.net/manual/en/openssl.installation.php 参考のため。
でページを作成します
phpinfo();
SSLは有効になっていますか?
他のヒント
私は同様の質問を探していました、そして、あなたはphp.iniファイルを編集する必要があることがわかりました、次の行を編集します
;extension=php_openssl.dll
セミコロンを削除すると正常に動作します
他の人にも役立つことを願っています:)
Gmail では config.yml にこれが必要です
迅速なメーラー:暗号化:TL
または次のものを置き換えます。- > setEncryption( 'ssl')by> setEncryption( 'tls')
SSLではありません
php 拡張機能から php_openssl モジュールを有効にする必要があります。編集するだけです php.ini ファイル
extension=php_openssl.dll
実際、次の構文を使用して、ポート25テストでTLSを使用するようアドバイスします。
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 25, 'tls')
->setUsername('007@gmail.com')
->setPassword('123');
sslで動作するようにphpを設定する必要があります
あなたの問題が解決されたことを願っていますが、私にとっては次のとおりです。
;extension=php_openssl.dll
私のphp.ini(win7でxampp1.7.7を実行している)には存在しませんでしたので、先に進んで拡張機能セクションに追加して、セミコロンを削除すると機能するはずです。