2017-06-19 168 views
0

我正嘗試使用Swift Mailer發送電子郵件Laravel,我一直試圖從最近3天,但No Luck
Laravel:Swift_TransportException無法與主機建立連接smtp.gmail.com

我GoDaddy的共享主機,我已經與Customer Support討論,他們表示沒有從那裏邊

問題,我無法找到什麼是錯的這個代碼。

已經推薦這篇文章,但沒有得到任何解決方案。

  1. Laravel - Connection could not be established with host smtp.gmail.com [ #0]
  2. Swift_TransportException Connection could not be established with host smtp.gmail.com
  3. Connection could not be established with host smtp.gmail.com [Connection timed out #110] in laravel 5.2
  4. How to resolve the error: Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)

代碼

$transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl") 
     ->setUsername('[email protected]') 
     ->setPassword('*****'); 

     $nam = 'abc'; 
     $from = '[email protected]'; 

     $message = \Swift_Message::newInstance($subject) 

     ->setFrom(array($from => $name)) 
     ->setTo(array($to)) 
     ->setBody($body); 
     $message->setContentType("text/html"); 
     $mailer = \Swift_Mailer::newInstance($transport); 
     $result = $mailer->send($message); 
     return $result; 



Please ignore Variable declaration, like $subject and ect.... 

Port Tried。

1. 465 
2. 587 
3. 80 
4. 25 
5. 110 (Gmail Commercial Email) 

它表示錯誤

消息:的fsockopen():無法連接到SSL://smtp.gmail.com:465 (連接被拒絕)

enter image description here

+0

你已經可以在你的Gmail帳戶不安全的應用程序?這通常阻礙了連接。 – FMashiro

+0

是的,它允許 –

+0

'Godaddy Shared hosting'這是你的問題 – Ian

回答

0

檢查您的smtp連接電子郵件,嘗試用谷歌電子郵件進行測試

smtp.gmail.com 端口:587 secureconnection:真

使谷歌的電子郵件安全connectino禁用

1

我已經使用GoDaddy的一個老服務器和我可以發送電子郵件。我不得不改變sendmail的路徑。你可以看到它在爲info.php - >

// Show all information, defaults to INFO_ALL 
phpinfo(); 

和搜索: 「sendmail_path」 ......

在我的情況sendmail_path是 「/ usr/sbin目錄/ sendmail的-t -i」

你應該把它放在配置/ mail.php:

/* 
    |----------------------------------------------------------------- 
    | Sendmail System Path 
    |----------------------------------------------------------------- 
    | 
    | When using the "sendmail" driver to send e-mails, we will need to know 
    | the path to where Sendmail lives on this server. A default path has 
    | been provided here, which will work well on most of your systems. 
    | 
    */ 

    'sendmail' => '/usr/sbin/sendmail -t -i', 
相關問題