首页 文章

Laravel:Swift_TransportException无法使用host smtp.gmail.com Build 连接

提问于
浏览
0

我正在尝试使用 Swift MailerLaravel 发送电子邮件,我一直在尝试过去3天但是 No Luck .

我有Godaddy共享主机,我已经与_1392703讨论了,他们说从那边没有问题

我无法找到此代码中的错误 .

已经提到这篇文章,但没有得到任何解决方案 .

代码

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

      $nam = 'abc';
      $from = 'my@gmail.com';

      $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

3 回答

  • 1

    我使用了godaddy的旧服务器,我可以发送电子邮件 . 我不得不改变sendmail的路径 . 你可以在info.php上看到它 - >

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

    并搜索:“sendmail_path”......

    就我而言 sendmail_path 是"/usr/sbin/sendmail -t -i"

    你应该把它放在config / 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',
    
  • 0

    检查您的smtp连接电子邮件,尝试使用谷歌电子邮件进行测试

    smtp.gmail.com port:587 secureconnection:true

    在谷歌电子邮件安全连接中禁用

  • 0

    我有一个解决方案 . 使用此配置:

    'mail' => [
            'class' => 'yii\swiftmailer\Mailer',
            'htmlLayout' => '@frontend/views/user/mail/layouts/html',
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp-relay.gmail.com',  // e.g. smtp.mandrillapp.com or smtp.gmail.com
                'username' => '',
                'password' => '',
                'port' => '465',
                'encryption' => 'ssl',
                'streamOptions' => [
                    'ssl' => [
                        'allow_self_signed' => true,
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                    ],
                ]
            ],
        ],
    

相关问题