【问题标题】:Add custom property to Mail in Laravel在 Laravel 中为邮件添加自定义属性
【发布时间】:2020-12-20 18:17:07
【问题描述】:

我正在尝试让 Postmark 的新 Message Streams 与 Laravel 一起使用。

有没有办法将属性 + 值 '"MessageStream": "notifications" 添加到使用 Laravel 邮件发送的电子邮件的 JSON 正文中?我猜我需要以某种方式扩展 Mailable 类来做到这一点。

理想情况下,我希望能够在我的 Mailable 类中执行以下操作:

DiscountMailable.php

public function build()
    {
        return $this->from('hello@example.com')
        ->markdown('emails.coupons.created')
        ->subject('???? Your Discount')
        ->with([
          'coupon' => $this->coupon,
        ])
        ->messageStream(
          'notifications',
        );

    }

【问题讨论】:

  • 你是否设法将消息流与 Laravel 一起使用?
  • 是的。我刚刚添加了以下内容:->withSwiftMessage(function ($message) { $message->getHeaders()->addTextHeader('X-PM-Message-Stream', 'notifications'); });

标签: php laravel email postmark


【解决方案1】:

只是为了确保这个问题有答案,这是使它工作的必要条件(它也适用于我今天在 Laravel 7 中的问题,我想为不同的邮件通知类型使用不同的邮戳流) .

public function build()
{
    return $this->from('hello@example.com')
        ->markdown('emails.coupons.created')
        ->subject('? Your Discount')
        ->with([
            'coupon' => $this->coupon,
        ])
        ->withSwiftMessage(function ($message) { 
            $message->getHeaders()
                ->addTextHeader('X-PM-Message-Stream', 'notifications')
        });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 2013-08-09
    • 1970-01-01
    • 2012-07-08
    相关资源
    最近更新 更多