cakephp 3.7如何设置电子邮件布局和模板

愤怒

如何设置电子邮件布局和模板

$email = new Email('default');
$email->setFrom($from)
      ->setTo('[email protected]')
      ->setSubject('Test email')
      ->setEmailFormat('html')
      ->viewBuilder()->setLayout('my-email-layout')
      ->setViewVars([
            'name' => Alex
       ])
       ->send('My message');

电子邮件打印

[protected] _viewBuilder => object(Cake\View\ViewBuilder) {
    [protected] _templatePath => null
    [protected] _template => ''
    [protected] _plugin => null
    [protected] _theme => null
    [protected] _layout => 'default'
    [protected] _autoLayout => null
    [protected] _layoutPath => null
    [protected] _name => null
    [protected] _className => 'Cake\View\View'
    [protected] _options => []
    [protected] _helpers => [
        (int) 0 => 'Html'
    ]
    [protected] _vars => []
}
愤怒

我想到了。viewBuilder必须是最后一个参数。和send()必须分别调用。

$email = new Email('default');
$email->setFrom($from)
      ->setTo('[email protected]')
      ->setSubject('Test email')
      ->setEmailFormat('html')
      ->setViewVars([
            'name' => Alex
       ])
      ->viewBuilder()
          ->setLayout('my-email-layout')
          ->setTemplate('default');

$email->send('My message');

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章