網路上不同的人做法:
http://shian420.pixnet.net/blog/post/344687356-%5Blaravel%5D-gmail-smtp-%E5%BE%9E%E8%A8%AD%E5%AE%9A%E5%88%B0%E7%99%BC%E4%BF%A1
自己測試用做法:
原本運作正常的PHP laravel mail突然開始跳出錯誤
laravel stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
Laravel 4.2的解決辦法:
Edit \vendor\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php
line 259 ish. comment out the $options = array(); and add the below.
//$options = array(); $options['ssl'] = array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true);
如果使用gmail 需要在調整:
https://myaccount.google.com/u/1/lesssecureapps?pli=1&pageId=none
gmail的安全性:[允許安全性較低的應用程式] 設定處於啟用狀態 這樣才能登入
PS用laravel設定寄信 app\config\mail.php設定裡面需要確定
'driver' ='smtp', 'host' ='smtp.gmail.com', 'username' ='xxxxxxxxxxxxxx', 'password' ='xxxxxxxxxxxx',自己寫的controller code
$from = ['email'=>'whitebaiw@gmail.com', 'name'=>'whitebaiw', 'subject'=>'主旨' ]; //填寫收信人信箱 $to = ['email'=>'zxcvbnm2749@gmail.com', 'name'=>'zxcvbnm2749']; //信件的內容(即表單填寫的資料) $data = [ 'subject'=>'主旨', 'msg'=>'訊息' ]; //寄出信件 Mail::send('web.message.mailShowView', $data, function($message) use ($from, $to) { $message->from($from['email'], $from['name']); $message->to($to['email'], $to['name'])->subject($from['subject']); });----------------------------------------------------------------------------------------------------------
如果是使用LARAVEL 5.2且使用ssl 方式寄信 需要調整.env 檔案:
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=465 MAIL_USERNAME=xxxxx@gmail.com MAIL_PASSWORD=xxxx MAIL_ENCRYPTION=ssl
沒有留言:
張貼留言