使用 Laravel 中的 php 变量发送邮件

Use php variables in Laravel to send mail

朋友们,我的控制器里有这段代码:

$name       =   Input::get('fname')." " .Input::get('lname');
$message    =   Input::get('message');
$email      =   Input::get('email');
$subject    =   Input::get('subject');
$phone      =   Input::get('phone');
$area       =   \App\Area::find(1)->name;
$ticket =   \App\Area::find(1)->ticket_sent;
Mail::send('help.send', [ 'Mmessage' => $message, 'Mname' => $name, 'Memail' => $email, 'Msubject' => $subject, 'Mphone' =>$phone, 'Marea' => $area, 'Mticket' => $ticket], function ($message)
    {
        $message->from('asd@gmail.com', 'Name');
        $message->to('support@mycompany.it');
        $message->subject('Support');

    });
$macroArea = MacroArea::find(1);
$macroArea->ticket_sent =$ticket+1;
$macroArea->save();
Session::flash('message', 'The message was successfully send. We will get back to you within 2 business days!');
return Redirect::to('helpDesk');

效果很好,但我正在尝试更改以下两行:

$message->from($email, $name);
$message->subject($subject);

但是没用。我究竟做错了什么?没看懂。

请检查代码,需要在"function ($message)"

后添加使用
$name      =   Input::get('fname')." " .Input::get('lname');
$message   =   Input::get('message');
$email     =   Input::get('email');
$subject   =   Input::get('subject');
$phone     =   Input::get('phone');
$area      =   \App\Area::find(1)->name;
$ticket    =   \App\Area::find(1)->ticket_sent;

Mail::send('help.send', [ 'Mmessage' => $message, 'Mname' => $name, 'Memail' => $email, 'Msubject' => $subject, 'Mphone' =>$phone, 'Marea' => $area, 'Mticket' => $ticket], function ($message) use ($email, $name,$subject)
    {
        $message->from($email, $name);
        $message->to('support@mycompany.it');
        $message->subject($subject);
    });
$macroArea = MacroArea::find(1);
$macroArea->ticket_sent =$ticket+1;
$macroArea->save();
Session::flash('message', 'The message was successfully send. We will get back to you within 2 business days!');
return Redirect::to('helpDesk');

您需要使用use() with anonymous functions传递变量:

.... function ($message) use ($email, $name) { ....