Laravel:发送包含输入数据的电子邮件

时间:2018-07-03 10:17:47

标签: php laravel

我对这个Laravel非常陌生。我正在尝试通过阅读从create.blade.php输入的电子邮件地址来发送回复电子邮件 但是出现这样的错误:

  

Symfony \组件\调试\异常\ FatalThrowableError   (E_RECOVERABLE_ERROR)参数2传递给   Illuminate \ Mail \ Mailer :: send()必须是数组类型object   给定的   /用户/ steveruru /新闻简报/新闻简报/ supticket /供应商/laravel/framework/src/Illuminate/Support/Facades/Facade.php   在第221行

TicketController:

public function index(){
        $inputs = Inputs::all();
        return view('index', [
            'inputs' => $inputs
        ]);
    }
    public function create(){
        return view('create');
    }
    public function store(Request $request)
    {
        $inputs = new Inputs();

        $inputs->inputName = $request->inputName;
        $inputs->inputAddress = $request->inputAddress;
        $inputs->inputBDO = Carbon::parse($request->inputBDO);
        $inputs->inputEmail = $request->inputEmail;
        $inputs->inputPhone = $request->inputPhone;
        $inputs->inputJob = $request->inputJob;

        $inputs->save();
        Mail::send('mail', $inputs, function ($message) use($request) {

            $message->from($request->inputName,$request->inputAdress);

            $message->to($request->inputEmail)->subject('Alt Support');

        });
        return redirect ('home');
    }
}

create.blade.php

<form action="{{ URL::to('/input') }}" method="POST">
        {!! csrf_field() !!}
        Name: <input type="text" name="inputName">
        Address: <input type="text" name="inputAddress">
        Birthday: <input type="date" name="inputBDO">
        Email: <input type="text" name="inputEmail">
        Phone: <input type="text" name="inputPhone">
        Job: <input type="text" name="inputJob">
        <br>
        <input type="submit" value="Add Input">
    </form>

路线

Route::get('/', 'TicketController@index');
Route::get('/input/create', 'TicketController@create');
Route::post('/input', 'TicketController@store');

1 个答案:

答案 0 :(得分:0)

Mail::send('mail', $inputs->inputEmail, function ($message) use($request) {

    $message->from($request->inputName,$request->inputAdress);

    $message->to($request->inputEmail)->subject('Alt Support');

});

“邮件发送第二个参数”必须是电子邮件数组或单个电子邮件字符串