[英]Laravel send email, error: Argument 2 passed to
I have a problem with send email with Laravel, it's my method:我在用 Laravel 发送电子邮件时遇到问题,这是我的方法:
public function store(CreateUserRequest $request){
$name = Input::get('name');
$imie = Input::get('imie');
$nazwisko = Input::get('nazwisko');
$email = array('email' => Input::get('email'));
$password = Input::get('password');
Mail::send(['name' => $name], function ($message) use ($name, $imie, $nazwisko, $email, $password) {
$message->from('us@example.com', 'System Magazyn');
$message->attach('Your temporary password: '.['password' => $password]);
$message->to(['email'=>$email])->subject('Rejestracja Magazyn');
});
User::create($request->all());
Session::flash('addUserOK', 'Użytkownik dodany poprawnie.');
return redirect('user');
}
This method saved to database new user.此方法保存到数据库新用户。 I want send email to new user with information on the correct registration and information with temporary password.
我想向新用户发送包含正确注册信息和临时密码信息的电子邮件。 I did as it is written in the documentation https://laravel.com/docs/5.2/mail#sending-mail and as it is in this topic: Laravel 4 from contact form to admin email , but still Laravel returned error:
我按照文档https://laravel.com/docs/5.2/mail#sending-mail和本主题中的说明做了: Laravel 4 from contact form to admin email ,但 Laravel 仍然返回错误:
FatalThrowableError in Mailer.php line 149: Type error: Argument 2 passed to Illuminate\\Mail\\Mailer::send() must be of the type array, object given, called in C:\\xampp\\htdocs\\kurwa_magazyn\\magazyn_michal\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Facades\\Facade.php on line 219
Mailer.php 第 149 行中的 FatalThrowableError:类型错误:传递给 Illuminate\\Mail\\Mailer::send() 的参数 2 必须是数组类型,给定的对象,在 C:\\xampp\\htdocs\\kurwa_magazyn\\magazyn_michal\\vendor\\ 中调用laravel\\framework\\src\\Illuminate\\Support\\Facades\\Facade.php 在第 219 行
EDIT:编辑:
This is form to register new user:这是注册新用户的表格:
{!! Form::open(['route' => 'user.store', 'method' => 'post', 'class' => 'form-horizontal']) !!}
{!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'Nazwa użytkownika...']) !!}<br />
{!! Form::text('imie', null, ['class' => 'form-control', 'placeholder' => 'Imię...']) !!}<br />
{!! Form::text('nazwisko', null, ['class' => 'form-control', 'placeholder' => 'Nazwwisko...']) !!}<br />
{!! Form::email('email', null, ['class' => 'form-control', 'placeholder' => 'Adres e-mail...']) !!}<br />
{!! Form::text('password', uniqid(), array('class' => 'form-control', 'placeholder' => 'Podaj hasło...')) !!}<br />
{!! Form::select('permissions', array('0' => 'Pracownik fizyczny', '2' => 'Magazynier', '3' => 'Demo użytkownik', '1' => 'Administrator'), NULL, ['class' => 'form-control']) !!}<br />
{!! Form::hidden('remember_token', bcrypt(uniqid(rand(0,9)))) !!}
{!! Form::submit('Dodaj', ['class' => 'btn btn-default']); !!}
{!! Form::close() !!}
I think the issue you have is in a weird combination of this:我认为您遇到的问题是这种奇怪的组合:
$email = array('email' => Input::get('email'));
and this而这
$message->to(['email'=>$email])->subject('Rejestracja Magazyn');
According to API docs method to
accepts either combination of email/name or or an array根据API文档方法
to
接受电子邮件/名称或一个或阵列的任组合
Try to change your code to:尝试将您的代码更改为:
$message->to($email)->subject('Rejestracja Magazyn');
Since you already defined that array earlier here:由于您已经在这里定义了该数组:
$email = array('email' => Input::get('email'));
I know this is an old question, but, for anyone with the same problem, the second argument of Mail::send
must be an array.我知道这是一个老问题,但是对于任何有同样问题的人来说,
Mail::send
的第二个参数必须是一个数组。 This array could contain any data that will be read in the view.该数组可以包含将在视图中读取的任何数据。
The code would be like this:代码如下:
$data = ['foo' => 'baz'];
Mail::send(['name' => $name], $data, function ($message) use ($name, $imie, $nazwisko, $email, $password) {
$message->from('us@example.com', 'System Magazyn');
$message->attach('Your temporary password: '.['password' => $password]);
$message->to(['email'=>$email])->subject('Rejestracja Magazyn');
});
Then, in the view, the variable $foo
could be printed:然后,在视图中,可以打印变量
$foo
:
<p>Variable foo: {{$foo}}</p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.