2017-05-23 57 views
0

我發現了一種通過Mailgun API延遲發送電子郵件的方法。我想知道如果外部HTML可以用某種方式包含在郵件中?Laravel使用Mailgun計時消息

我現在做這樣的:

$mgClient->sendMessage($domain, array(
    'from' => 'XY<[email protected]>', 
    'to'  => 'XY<[email protected]>', 
    'subject' => trans('content.subject_confirm_event_registration'), 
    'html' => '<myHtmlCode />', 
    'o:deliverytime' => Carbon::now()->hours(2)->toRfc2822String() 
)); 

但問題是,當我嘗試任何複雜的,它具有像100行代碼,它看起來並不好,我想一個解決方案在那裏我可以把外部文件中,以便它看起來像這樣:

$mgClient->sendMessage($domain, array(
    'from' => 'XY<[email protected]>', 
    'to'  => 'XY<[email protected]>', 
    'subject' => trans('content.subject_confirm_event_registration'), 
    'html' => file.blade.php 
    'o:deliverytime' => Carbon::now()->hours(2)->toRfc2822String() 
)); 
+0

也許laravel梅勒可以幫助你嗎? 您也可以延遲在隊列中發送電子郵件。 – skido

+0

也許,但是我使用Mailgun後有一個原因:) – Norgul

+0

但是laravel有Mailgun Swift Transport驅動程序 – skido

回答

0

,您可以手動使用view()->render()渲染視圖。

Illuminate\View\View::render()返回視圖的字符串內容。它也用於類'__toString()方法中,該方法允許您回顯View對象。

$mgClient->sendMessage($domain, array(
    'from' => 'XY<[email protected]>', 
    'to'  => 'XY<[email protected]>', 
    'subject' => trans('content.subject_confirm_event_registration'), 
    'html' => view('some.template', $data)->render() 
    'o:deliverytime' => Carbon::now()->hours(2)->toRfc2822String() 
));