Laravel 4 - 邮件发送(变量未定义)

时间:2016-01-08 11:35:53

标签: php laravel laravel-4

尝试使用Laravel 4.2 发送确认电子邮件。但是在视图中遇到错误

  

未定义的变量:booking_data

我试图传递以下数据数组:

["from"]=>
  string(7) "Gatwick"
  ["to"]=>
  string(8) "Aberdeen"
  ["leaving"]=>
  string(21) "Friday, 15 July, 2016"
  ["returning"]=>
  string(24) "Wednesday, 20 July, 2016"
  ["price"]=>
  string(2) "53"
  ["hotel"]=>
  string(9) "Four Star"
  ["date_start"]=>
  string(10) "2016-07-15"
  ["date_end"]=>
  string(10) "2016-07-20"
  ["insurance"]=>
  string(0) ""
  ["num_travellers"]=>
  string(1) "1"
  ["car_hire"]=>
  string(0) ""
  ["baggage"]=>
  string(0) ""
  ["car_hire_days"]=>
  string(0) ""
  ["flight_cost"]=>
  string(2) "53"
  ["new_cost"]=>
  string(6) "383.00"
  ["hotel_transport"]=>
  string(0) ""
  ["passengers"]=>
  array(1) {
    [0]=>
    array(5) {
      ["firstname"]=>
      string(6) "Stuart"
      ["surname"]=>
      string(8) "Blackett"
      ["address2"]=>
      string(17) "Line 1"
      ["town"]=>
      string(12) "Town"
      ["passportnumber"]=>
      string(2) "TS"
    }
  }
  ["user_email"]=>
  string(27) "xyz@mail.co.uk"
  ["user_phone"]=>
  string(2) "01"

我目前的Laravel控制器代码是:

// Create View Confirming Payment....
$booking_data = Session::all();

// Send Confirmation To User & Site Admin...
$user_email = Session::get('user_email');

Mail::send('emails.confirmation', $booking_data, function($message) use ($booking_data)
{
    $message->from('xyz@mail.co.uk', 'In The Air Deals');

    $message->to(Session::get('user_email'))
        ->cc('xyz@mail.co.uk')
        ->subject('Booking Confirmation from In The Air Deals');
});

在视图中我使用刀片并执行以下操作:

@foreach ($booking_data['passengers'] as $passenger)
   <tr>
   <td>Name:</td>
   <td>
   {{ $passenger->firstname }}
   {{ $passenger->surname }}
   </td>
   </tr>
   <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   </tr>
   <tr>
   <td>Address:</td>
   <td>
   {{ $passenger->address1 }}
   <br />
   {{ $passenger->address2 }}
   {{ $passenger->town }}
  </td>
 </tr
@endforeach

我需要做些什么,要将预订数据传递给视图吗?

由于

1 个答案:

答案 0 :(得分:1)

试试这个:

@foreach ($passengers as $passenger)
   <tr>
   <td>Name:</td>
   <td>
   {{ $passenger->firstname }}
   {{ $passenger->surname }}
   </td>
   </tr>
   <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   </tr>
   <tr>
   <td>Address:</td>
   <td>
   {{ $passenger->address1 }}
   <br />
   {{ $passenger->address2 }}
   {{ $passenger->town }}
  </td>
 </tr
@endforeach