0
votes

I have a problem with send email with Laravel, it's my method:

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('[email protected]', '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:

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

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() !!}
2

2 Answers

0
votes

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

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'));
0
votes

I know this is an old question, but, for anyone with the same problem, the second argument of Mail::send must be an array. 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('[email protected]', '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:

<p>Variable foo: {{$foo}}</p>