2017-06-19 75 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', 
相关问题