使用Laravel使用Mailgun发送电子邮件时出错

问题描述 投票:0回答:2

我正在尝试向我的Laravel Web App发送邀请电子邮件,其中还必须传递一些参数。我无法发送电子邮件,并猜测问题不在于我的配置。有人可以帮我吗?

这是我将邀请发送到电子邮件的表单:

{!! Form::open(['method'=>'post', 'action'=>'AdminUserController@store']) !!}
    <input type="hidden" name="is_active" value="0">
    <input type="hidden" name="house_id" value="{{Auth::user()->house->id}}">
    <input type="hidden" name="role_id" value="2">
    <div class="form-group' has-error' : '' }}">
        <div class="col-md-6">
            {!! Form::text('email',null,['class'=>'form-control', 'placeholder'=>'Email']) !!}
        </div>
    </div>
    <div class="form-group">
        {!! Form::submit('Invite', ['class'=>'btn-primary small']) !!}
    </div>
{!! Form::close() !!}

这是路由器:

Route::post('/admin/user/store', 'AdminUserController@store')->name('admin/user/store');

这是负责所有逻辑AdminUserController @ store的控制器功能:

public function store(Request $request)
{
    $data = [
            'title'=>'Invitation',
            'content'=>'You are invited to try Housing Around App',
            'is_active'=> $request->input('is_active'),
            'house_id' => $request->input('house_id'),
            'role_id'=>$request->input('role_id'),
            'email'=>$request->input('email')
            ];

    $to = $data['email'];

    Mail::send('users.user.create',$data, function ($message){
        $message->to('to', 'Housing Around')->subject('Invitation');
    });

    return redirect('home');
}

这些是我对Mailgun的配置:

.env文件

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster@sandbox**************************.mailgun.org
MAIL_PASSWORD=44****************************************c
MAILGUN_DOMAIN=sandboxf6**************************.mailgun.org
MAILGUN_SECRET=key-4******************************0

我的mail.php

'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
    'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
    'name' => env('MAIL_FROM_NAME', 'Housing Around App'),
],
'username' => env('postmaster@sandbox*********************.mailgun.org'),
'password' => env('44**************************c'),

我的services.php

'mailgun' => [
        'domain' => env('sandbox*******************.mailgun.org'),
        'secret' => env('key-4*************************0'),
    ],

不过,它不起作用。我错过了什么吗?

刀片文件

<html>

<head>


</head>
<body style="background: black; color: white">

<h1>Housing Around Invitation</h1>

<p></p>

</body>
</html>
php laravel mailgun
2个回答
0
投票

使用$代替'to',然后让匿名函数知道它。

function ($message) use ($to)

-2
投票

尝试在更改.env文件后运行

php artisan config:cache 
© www.soinside.com 2019 - 2024. All rights reserved.