简体   繁体   English

Laravel 5.2电子邮件未发送

[英]Laravel 5.2 Emails not sending out

Trying to send an activation mail after registering on the website (using the Auth Controller). 在网站上注册后尝试发送激活邮件(使用Auth Controller)。

Here's the code of my controller: 这是我的控制器的代码

protected function create(array $data)
{
    $data['activation_code'] = str_random(20);

    return User::create([
        'firstname' => $data['firstname'],
        'lastname' => $data['lastname'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'activation_code' => $data['activation_code'],
    ]);

    Mail::send('emails.register', $data, function($message) use ($data)
    {
        $message->from('info@foodtruckbestellen.be', "Foodtruckbestellen.be");
        $message->subject("Welkom bij foodtruckbestellen.be");
        $message->to($data['email']);
    });
}

and here's the code of my email view: 这是我的电子邮件视图的代码

<h1>Hi {{ $data['firstname'] }}</h1>
<p>
    Link = <a href="http://192.168.33.10/register/activate?code={{ $data['verification_code'] }}'">CLICK ME</a>
</p>

Part of my .env : 我的.env的一部分

MAIL_DRIVER=mail
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

The user get's saved in the DB without any problem, but my email isn't sending out. 用户被保存到数据库中没有任何问题,但是我的电子邮件没有发送出去。 I don't receive any errors, so I'm not sure what's going on. 我没有收到任何错误,所以我不确定发生了什么。

You need to setup your .env file. 您需要设置您的.env文件。 Just register at mailtrap and copy/paste the the username and password from mailtrap to the .env file. 只需在mailtrap上注册,然后将用户名和密码从mailtrap复制/粘贴到.env文件即可。

Edit: 编辑:

        Mail::send('email.register', ['data' => $data], function ($message) use ($data) {
        $message->from('info@foodtruckbestellen.be', 'Foodtruckbestellen.be');
        $message->to($data['email']);
        $message->subject('Welkom bij foodtruckbestellen.be);
    });

Try this code. 试试这个代码。 I think you must use use and $data must be inside array. 我认为您必须使用use并且$data必须在数组内部。 Hope this was helpful. 希望这会有所帮助。

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

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