简体   繁体   English

无法发送电子邮件Laravel

[英]Can't send email Laravel

I'm trying to send email after user registration and I get an error: 我尝试在用户注册后发送电子邮件,但出现错误:

Connection could not be established with host smtp.gmail.com [Connection timed out #110] 无法与主机smtp.gmail.com建立连接[连接超时#110]

I'm using Ubuntu 16.04 server. 我正在使用Ubuntu 16.04服务器。 Everything was ok on localhost. 在本地主机上一切正常。
Command 命令

openssl s_client -connect google.com:443 -tls1_2

returns OK, so I guess 587 port is opened to send email. 返回OK,所以我猜想587端口已打开以发送电子邮件。
My .env : 我的.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=***@gmail.com
MAIL_PASSWORD=*** //(not the same as I used on local machine)
MAIL_ENCRYPTION=tls

config\\mail.php : config\\mail.php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

    'port' => env('MAIL_PORT', 587),

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '***@gmail.com'),
        'name' => env('MAIL_FROM_NAME', '***'),
    ],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

EDIT#1: also I have connected problem. EDIT#1:我也有连接问题。 While trying to seed this 在尝试播种时

public function run()
    {
        $defaultUser = User::create([
            'name' => 'user',
            'email' => 'user@mail.com',
            'password' => bcrypt('123123'),
            'verified' => 1
        ]);

        $defaultAdmin = User::create([
            'name' => 'admin',
            'email' => 'admin@mail.com',
            'password' => bcrypt('123123'),
            'verified' => 1
        ]);

        $userRole = Role::create([
            'name' => 'user',
            'display_name' => 'user',
            'description' => 'user',
        ]);

        $adminRole = Role::create([
            'name' => 'admin',
            'display_name' => 'admin',
            'description' => 'admin',
        ]);

        $defaultUser->attachRole($userRole); //zizaco-entrus RBAC package
        $defaultAdmin->attachRole($adminRole);
    }

only $defaultUser seeds (I have an event which fires after user is stored and send an verification mail to him). $defaultUser种子(我有一个事件,会在存储用户并向其发送验证邮件后触发)。 I get an error 我得到一个错误

In StreamBuffer.php line 269: 在StreamBuffer.php第269行中:

Connection could not be established with host smtp.gmail.com [Connection ti med out #110] 无法与主机smtp.gmail.com建立连接[连接编号为110的连接]

EDIT#2: telnet smtp.gmail.com 587 does not response. 编辑#2: telnet smtp.gmail.com 587不响应。

EDIT#3: sudo ufw status : EDIT#3: sudo ufw status

Status: active

To                         Action      From
--                         ------      ----
Apache Full                ALLOW       Anywhere
587/tcp                    ALLOW       Anywhere
465/tcp                    ALLOW       Anywhere
22                         ALLOW       Anywhere
80                         ALLOW       Anywhere
443                        ALLOW       Anywhere
21/tcp                     ALLOW       Anywhere
587                        ALLOW       Anywhere
Apache Full (v6)           ALLOW       Anywhere (v6)
587/tcp (v6)               ALLOW       Anywhere (v6)
465/tcp (v6)               ALLOW       Anywhere (v6)
22 (v6)                    ALLOW       Anywhere (v6)
80 (v6)                    ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)
21/tcp (v6)                ALLOW       Anywhere (v6)
587 (v6)                   ALLOW       Anywhere (v6)

EDIT#4: 编辑#4:
My new Gmail app key I created for this project is still unused. 我为此项目创建的新Gmail应用程序密钥仍未使用。

I tried this answer : 我尝试了这个答案

In AbstractSmtpTransport.php line 419: 在AbstractSmtpTransport.php行419中:
Expected response code 220 but got code "", with message "" 预期的响应代码为220,但得到的代码为“”,并带有消息“”

Also this answer didn't help. 同样, 这个答案也无济于事。

EDIT#5: checked smtp permission on server dashboard. EDIT#5:在服务器仪表板上检查了smtp权限。 Sorry for disturbing guys. 不好意思,伙计们。

I have experience with GoDaddy servers that limit the number of relays your server can send out per day. 我在GoDaddy服务器方面有经验,它限制了服务器每天可以发送的中继数量。

Google Cloud Platform prohibits the sending of emails altogether by blocking the commonly used SMTP email ports. Google Cloud Platform通过阻止常用的SMTP电子邮件端口来完全禁止发送电子邮件。 They do have agreements with the saas email providers to raise the number of free emails you can send. 他们确实与saas电子邮件提供商达成协议,以增加您可以发送的免费电子邮件的数量。 For example, I use mailgun and instead of sending only 10,000 emails per month for free, I can send 30,000 emails. 例如,我使用mailgun,而不是每月免费发送10,000封电子邮件,而是发送30,000封电子邮件。 I really like sending the emails this way because they have higher deliverability and allow us to track clicks, unsubscribes, views, etc easier. 我真的很喜欢以这种方式发送电子邮件,因为它们具有更高的可传递性,并允许我们更轻松地跟踪点击,退订,查看等。 Bottom line, I recommend subscribing to one of these services. 最重要的是,我建议订阅其中一项服务。

I suspect that Scaleway is limiting you as well. 我怀疑Scaleway也会限制您。 Basically, any cloud server hosting service has a liability with emails. 基本上,任何云服务器托管服务都有电子邮件责任。 Especially with shared hosting 1 spammer can flag multiple users across the same server and region as spammers even though they may be innocent. 尤其是在共享主机的情况下,垃圾邮件发送者可以将同一服务器和区域中的多个用户标记为垃圾邮件发送者,即使他们可能是无辜的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM