您好,登錄后才能下訂單哦!
這篇文章主要介紹“l(fā)aravel5發(fā)送ssl郵箱報(bào)錯(cuò)怎么解決”的相關(guān)知識(shí),小編通過實(shí)際案例向大家展示操作過程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“l(fā)aravel5發(fā)送ssl郵箱報(bào)錯(cuò)怎么解決”文章能幫助大家解決問題。
由于laravel5默認(rèn)使用的是 swiftmailer 擴(kuò)展。發(fā)送使用的是 stream 其中并未對(duì)ssl提供證書等內(nèi)容配置,所以當(dāng)使用ssl時(shí)又未指定證書時(shí)會(huì)錯(cuò):
Connection could not be established with host *******.com [ #0]
連接失敗,造成錯(cuò)誤的地方:vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php 類
Swift_Transport_StreamBuffer 的 _establishSocketConnection 方法在調(diào)用 stream_context_create 時(shí)缺少證書相關(guān)配置。
其中需要注意的是 verify_peer_name 要求驗(yàn)證證書名默認(rèn)值為true,這里是問題所以,當(dāng)沒有指定證書時(shí)該值會(huì)影響連接驗(yàn)證失敗導(dǎo)致整個(gè)連接失敗。因此需要修改代碼并把 verify_peer_name 設(shè)置為 false。
但其增加了兩行代碼把 verify_peer 和 verify_peer_name 都設(shè)置為false 。依文檔中看,verify_peer 默認(rèn)值已經(jīng)是 false ,所以可以不加。
修改代碼如下:
/** * Establishes a connection to a remote server. */ private function _establishSocketConnection() { $host = $this->_params['host']; if (!empty($this->_params['protocol'])) { $host = $this->_params['protocol'].'://'.$host; } $timeout = 15; if (!empty($this->_params['timeout'])) { $timeout = $this->_params['timeout']; } $options = array(); if (!empty($this->_params['sourceIp'])) { $options['socket']['bindto'] = $this->_params['sourceIp'].':0'; } //在這里增加代碼,修改默認(rèn)值 $options['ssl']['verify_peer_name'] = FALSE; $this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options)); if (false === $this->_stream) { throw new Swift_TransportException( 'Connection could not be established with host '.$this->_params['host']. ' ['.$errstr.' #'.$errno.']' ); } if (!empty($this->_params['blocking'])) { stream_set_blocking($this->_stream, 1); } else { stream_set_blocking($this->_stream, 0); } stream_set_timeout($this->_stream, $timeout); $this->_in = &$this->_stream; $this->_out = &$this->_stream; }
關(guān)于“l(fā)aravel5發(fā)送ssl郵箱報(bào)錯(cuò)怎么解決”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。