使用Laravel发送电子邮件

时间:2018-01-24 08:55:46

标签: php laravel email

我正在尝试在电子邮件中发送带有数组foreach(填充表格)的视图。

Mail::send(['estancias.plantilla'], ['estancias'=>$array], function ($message) use ($from,$to) {
     $message->from($from)->to($to);
});

返回

  

未定义偏移量:1,但我不确定错误是什么。

数据阵列没问题。

所以问题是为什么我不能用电子邮件中的数据发送此视图?

编辑:

阵列的DD展开:

Collection {#2048 ▼
      #items: array:1082 [▼
        0 => Inventory {#2049 ▼
          #connection: "oracle_da"
          +table: "INVENTORY"
          #primaryKey: "id"
          #perPage: 15
          +incrementing: true
          +timestamps: true
          #attributes: array:7 [ …7]
          #original: array:7 [ …7]
          #relations: []
          #hidden: []
          #visible: []
          #appends: []
          #fillable: []
          #guarded: array:1 [ …1]
          #dates: []
          #casts: []
          #touches: []
          #observables: []
          #with: []
          #morphClass: null
          +exists: true
        }
        1 => Inventory {#2050 ▶}
        2 => Inventory {#2051 ▶}
        3 => Inventory {#2052 ▶}
        4 => Inventory {#2053 ▶}
        5 => Inventory {#2054 ▶}
        6 => Inventory {#2055 ▶}
        7 => Inventory {#2056 ▶}
        8 => Inventory {#2057 ▶}
        9 => Inventory {#2058 ▶}
        10 => Inventory {#2059 ▶}

编辑2:

Estancias.plantilla

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="{{ asset('/css/bootstrap.css') }}" rel="stylesheet"/>
    <title>Estancias</title>
    <style>
    td,th{
        text-align:center;
    }
    </style>
</head>
<body>
<?php
    $codigoActual="";
?>
<div class="row">
    <div class="col-md-10 col-md-offset-1">
        <div class="page-header">
            <h1>Listado de estancias</h1>
        </div>
        <table class="table table-striped table-bordered table-hover">
            <thead>
                <th width="col-lg-1">Código</th>
                <th width="col-lg-1">In Date</th>
                <th width="col-lg-1">Cntr No</th>
                <th width="col-lg-1">VSL</th>
                <th width="col-lg-1">Call Year</th>
                <th width="col-lg-1">Call Seq</th>
                <th width="col-lg-1">Diferencia</th>
            </thead>
            <tbody>
            @foreach($estancias->sortBy('agent_code')  as $estancia)
                @if($codigoActual==$estancia->agent_code)
                <tr>
                    <td></td>
                    <td>{{isset ($estancia->in_date)?\Carbon\Carbon::parse($estancia->in_date)->format('d-m-Y H:i:s'):''  }}</td>
                    <td>{!!$estancia->cntr_no ? $estancia->cntr_no:''!!}</td>
                    <td>{!!$estancia->vsl_cd ? $estancia->vsl_cd:''!!}</td>
                    <td>{!!$estancia->call_year ? $estancia->call_year:''!!}</td>
                    <td>{!!$estancia->call_seq ? $estancia->call_seq:''!!}</td>
                    <td>{!!$estancia->diferencia ? $estancia->diferencia:''!!}</td>
                </tr>
                @else  
                <?php  $codigoActual=$estancia->agent_code; ?>
                <tr>
                    <td>{{$codigoActual}}</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                @endif
            @endforeach
            </tbody>
        </table>
        <p>Se han encontrado <b>{{count($estancias)}}</b> elementos.</p>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

从第一个参数中删除Mail::send('estancias.plantilla', ['estancias'=>$array], function ($message) use ($from,$to) { $message->from($from)->to($to); });

{{1}}