0

我正在使用 Mail::send() Laravel 5.2 和 email.blade.php 作为参数,它之前从数据库中动态获取其 html 内容。发送电子邮件后到达空。

但是,如果我将 HTML 内容直接放入 email.blade.php,它就可以正常工作。

我怎么能用数据库做呢?

*** 编辑:

现在它工作了一点。但是id模板仍然没有被id值替换。

// From database
<table width="100%">
  <tr>
    <td></td>
    <td>
      Your ID: {{ $data->your_id }}
    </td>
    <td></td>
  </tr>
</table>

// email.blade.php
{{ $data->mailtext_DB }}


// Call Mail::send
$data = [
    'sender_email'    => 'info@google.com',
    'mailtext_blade'  => email,
    'sender_name'     => 'Google',
    'receiver_email'  => 'user@google.com',
    'receiver_name'   => 'User One',
    'subject'         => 'Hello User!',
    'mailtext_DB'     => $HTML_text_from_DB,  // this comes from the database
    'your_id'         => $id_no
];    

// convert $data to an object for use in Mail::send
// ...                                                 

$status = Mail::send(
    $data->mailtext_blade,
    [ 'data' => $data ],
    function ( $m ) use ( $data ) {
        $m->from( $data->sender_email, $data->sender_name );
        $m->to( $data->receiver_email, $data->receiver_name )->subject( $data->subject );
    }
);         

我收到的邮件内容是:您的 ID:{{ $data->your_id }}

但我期待:您的 ID:123546

困难在于视图应该很小,例如:

// email.blade.php
{{ $data->mailtext_DB }}        
4

0 回答 0