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

查看:32
本文介绍了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');
});

有谁知道如何做到这一点?

Does anyone know how this can be done?

推荐答案

据我所知,如果不访问 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.

正如评论中指出的那样,不需要 getSwiftMessage 方法,因为在 IlluminateMailMessage__call 魔术方法code> 我忽略的类.

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

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

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

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