自定义电子邮件标题在Laravel 4 [英] Custom Email Headers in Laravel 4

查看:89
本文介绍了自定义电子邮件标题在Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法在Laravel 4 docs/Email API中找到可以在电子邮件中添加自定义标头的方法.

I can't seem to locate the method within the Laravel 4 docs/Email API where I can add custom headers to an email.

例如:

Mail::send('emails.welcome', $data, function($message)
{
    $message->to('foo@example.com', 'John Smith')->subject('Welcome!');
    $message->headers('X-Tags', 'tag1 tag2 tag3');
});

有人知道该怎么做吗?

推荐答案

据我所知,如果不进入Swift Mailer,就无法添加自定义标头.

As far as I know there's no way to add custom headers without reaching in to Swift Mailer.

尝试这样的事情.

$message->getSwiftMessage()->getHeaders()->addTextHeader('X-Tags', 'tag1 tag2 tag3');

它看起来并不漂亮,但是通过寻找应该解决问题的源代码来解决.

It doesn't look pretty but from looking through the source that should do the trick.

正如下面的注释所指出的,由于我忽略了Illuminate\Mail\Message类上的__call魔术方法,因此不需要getSwiftMessage方法.

As pointed out in the comments below the getSwiftMessage method isn't required as there is an __call magic method on the Illuminate\Mail\Message class that I overlooked.

$message->getHeaders()->addTextHeader('X-Tags', 'tag1 tag2 tag3');

这篇关于自定义电子邮件标题在Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆