0

我已经构建了一个 cakePHP3 应用程序,我正在寻找有关以下情况的一些建议。电子邮件配置设置如下,以便在创建新订单时发送邮件。

public function orderCreated($order, array $attachments = [])
    {
        $email = $this
            ->locale($order->customer->language)
            ->to($order->customer->email)
            ->from(Configure::read('Webshop.email'), Configure::read('Webshop.name'))
            ->subject(__('Confirmation of your order {0}', $order->nr))
            ->template('orders' . DS . 'order_created')
            ->set(['order' => $order])
            ->attachments($attachments);

        return $email;
    }

多年来一直运行良好,但我想为这封特定的电子邮件(和其他电子邮件)添加一些新功能。如果他们愿意,管理员应该能够覆盖 orders/order_created.ctp 模板的内容,这样他们就可以自己定义这封电子邮件的内容。所以他们不必依赖我提供的 order_created.ctp 模板中的相同内容。

创建用于保存他们自己的电子邮件的 UI 不是问题。但是我真的不知道如何将覆盖的内容提供给 cakePHP3 邮件程序。我试过设置

 ->template(false)
 ->message($new_content)

但这没有帮助。邮件未到达邮箱,因为正文为空。

谢谢。

4

1 回答 1

1

我想我会选择这样的东西:

->template('orders' . DS . 'order_created_custom')
->set(['order' => $order, 'content' => $new_content])

然后在新的order_created_custom.ctp你会输出$content. 这使您可以选择基于 对内容进行一些文本替换$order,以及可能具有标准称呼或签名之类的内容。

于 2018-03-01T23:21:42.340 回答