2016-08-31 8 views
4

Iメイトを送信するために、私は私のコントローラでこのコードがあります:それはとても良い作品使用PHPの変数は、メールに

$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('[email protected]', 'Name'); 
     $message->to('[email protected]'); 
     $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); 

しかし、動作しません。私は間違って何をしていますか?わかりません。

+0

またはLaravel 5.3、使用することを検討してくださいメールの送信が書き直され、現在ははるかに簡単です:https://laravel.com/docs/5.3/mail – mazedlx

答えて

4

、コードを確認してくださいあなたは、変数を渡すためにuse() with anonymous functionsを使用する必要が

$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('[email protected]'); 
     $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'); 
+0

@ therock24あなたが試してみました – rahul

+0

あなたが仲間に感謝、私は今試して – therock24

+0

それはあなたが私の答え@ therock24 – rahul

4

"機能($メッセージ)" の後に使用を追加する必要があります。

.... function ($message) use ($email, $name) { .... 
関連する問題