试图让 Laravel 5 电子邮件工作 [英] Trying to get Laravel 5 email to work

查看:28
本文介绍了试图让 Laravel 5 电子邮件工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过输入 URL 向指定用户发送电子邮件,但出现以下错误:

I'm trying to send an email to a specified user by typing in the URL, but I'm getting the following error:

AbstractSmtpTransport.php 第 383 行中的 Swift_TransportException:预期响应代码 250,但得到代码530",消息为530 5.7.1需要认证

Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required

到目前为止,我只是想让它与 Gmail 一起使用.我怎样才能让它工作?

So far I'm just trying to get it to work with Gmail. How can I get this to work?

这是我目前所拥有的:ma​​il.php

<?php
    return [
        'driver' => env('MAIL_DRIVER',' smtp'),
        'host' => env('MAIL_HOST', 'smtp.gmail.com'),
        'port' => env('MAIL_PORT', 587),
        'from' => ['address' =>"MyUsername@gmail.com" , 'name' => "example"],
        'encryption' => 'tls',
        'username' => env('MyUsername@gmail.com'),
        'password' => env('MyPassword'),
        'sendmail' => '/usr/sbin/sendmail -bs',
        'pretend' => false,
    ];

这是我在路线中的内容:

This is what I have in the routes:

Route::get('test', function() {
    Mail::send('Email.test', [], function ($message) {
        $message->to('example@gmail.com', 'HisName')->subject('Welcome!');
    });
});

这是我的控制器中的内容:

This is what I have in my controller:

class MailController extends Controller
{
    public function Sending_Email()
    {
        $this->call('GET','Email.test');
        return View('Email.test');
    }
}

这就是我的 .env 文件中的内容:

And this is what is in my .env file:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=MyUsername@gmail.com
MAIL_PASSWORD=MyPassword

推荐答案

我知道它现在对你有用@Vantheman6 但是这对我有用,以防其他人也一样.

I know it's working for you now @Vantheman6 but this is what worked for me in case it's the same for someone else.

我在 .env 文件中添加了我正在使用的邮件服务的详细信息.所以请确保以下细节

I added to my .env file the details of the mail service I am using. So make sure the following details

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=MyUsername@gmail.com
MAIL_PASSWORD=MyPassword

在 .env 文件中是准确的.

in the .env file are accurate.

注意:不要忘记在编辑 .env 文件后重新启动您的服务器,以便它会选择您放入其中的新数据.

使用以下命令清除配置缓存:

php artisan config:cache

如果您不重新启动服务器,即使您进行了可能导致此错误的更改,.env 文件仍将继续向应用显示旧邮件数据.

If you don't restart your server, the .env file will still continue to present the old mail data to the app even though you have made changes that can cause this error.

这篇关于试图让 Laravel 5 电子邮件工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆