2016-03-15 37 views
1

我使用SwiftmailerSymfony 2.8從Gmail帳戶發送郵件到Outlook帳戶發送郵件。 我用在我的控制器代碼:啓用與Swiftmailer

$message = \Swift_Message::newInstance() 
    ->setSubject('Test Email') 
    ->setFrom('[email protected]') 
    ->setTo('[email protected]') 
    ->setBody(
     $this->renderView(

      'QualifBundle:Mails:Welcome.html.twig' 
      ), 
     'text/html' 
    ); 
$this->get('mailer')->send($message); 

配置文件:

# Swiftmailer Configuration 
swiftmailer: 
    transport: %mailer_transport% 
    encryption: %mailer_encryption% 
    auth_mode: %mailer_auth_mode% 
    host:  %mailer_host% 
    username: %mailer_username% 
    password: %mailer_password% 
    spool:  { type: memory } 

參數陽明:

mailer_username: [email protected] 
mailer_password: xxxxxxxxx 
mailer_transport: smtp 
mailer_encryption: ssl 
mailer_auth_mode: login 
mailer_host: smtp.gmail.com 

我設法解決SSL錯誤,現在有了這個代碼,我應用程序運行沒有異常,但郵件未收到(也許甚至還沒有被髮送) 我該如何解決或指紋呢?

更新 我刪除spool:{ type: memory }讓郵件獲得直接發送,我得到這個例外。

Connection could not be established with host 127.0.0.1 [Connection refused #111] 

我的主機應該是smtp.gmail.com不是localhost任何想法?

解決方案 我通過黑客進入供應商的文件解決我的問題,我知道這是不是最好的解決辦法,但至少我可以發送郵件。

尋找​​3210功能在StreamBuffer.php應該在這個路徑/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport進入項目。 並添加那些以下行逃脫SSL驗證:

//... 
$options = array(); 
if (!empty($this->_params['sourceIp'])) { 
    $options['socket']['bindto'] = $this->_params['sourceIp'].':0'; 
} 
//Add those two lines 
$options['ssl']['verify_peer'] = FALSE; 
$options['ssl']['verify_peer_name'] = FALSE; 
//... 

然後我重新啓動我郵寄就像一個魅力

回答

0

解決方案 我通過入侵供應商的文件解決了我的問題,我知道這不是最好的解決方案,但至少我可以發送郵件。

尋找​​3210功能在StreamBuffer.php應該在這個路徑/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport進入項目。 並添加那些以下行逃脫SSL驗證:

//... 
$options = array(); 
if (!empty($this->_params['sourceIp'])) { 
    $options['socket']['bindto'] = $this->_params['sourceIp'].':0'; 
} 
//Add those two lines 
$options['ssl']['verify_peer'] = FALSE; 
$options['ssl']['verify_peer_name'] = FALSE; 
//... 

然後我重新啓動我郵寄的作品就像一個魅力

0

另一種方式圍繞瀏覽器:上述

$opt['ssl']['verify_peer'] = FALSE; 
$opt['ssl']['verify_peer_name'] = FALSE; 

$this->get('swiftmailer.mailer.default.transport.real')->setStreamOptions($opt); 

代碼中前放置:\Swift_Message::newInstance()