Skip to content

Commit 3a0f829

Browse files
kbondtaylorotwell
andauthored
[9.x] ability to add tags/metadata to Emails/Notifications (#40783)
* ability to add tags/metadata to Emails/Notifications * formatting * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent 2667e69 commit 3a0f829

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/Illuminate/Mail/Mailable.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
use PHPUnit\Framework\Assert as PHPUnit;
2121
use ReflectionClass;
2222
use ReflectionProperty;
23+
use Symfony\Component\Mailer\Header\MetadataHeader;
24+
use Symfony\Component\Mailer\Header\TagHeader;
25+
use Symfony\Component\Mime\Email;
2326

2427
class Mailable implements MailableContract, Renderable
2528
{
@@ -870,6 +873,33 @@ public function attachData($data, $name, array $options = [])
870873
return $this;
871874
}
872875

876+
/**
877+
* Add a tag header to the message when supported by the underlying transport.
878+
*
879+
* @param string $value
880+
* @return $this
881+
*/
882+
public function tag($value)
883+
{
884+
return $this->withSymfonyMessage(function (Email $message) use ($value) {
885+
$message->getHeaders()->add(new TagHeader($value));
886+
});
887+
}
888+
889+
/**
890+
* Add a metadata header to the message when supported by the underlying transport.
891+
*
892+
* @param string $key
893+
* @param string $value
894+
* @return $this
895+
*/
896+
public function metadata($key, $value)
897+
{
898+
return $this->withSymfonyMessage(function (Email $message) use ($key, $value) {
899+
$message->getHeaders()->add(new MetadataHeader($key, $value));
900+
});
901+
}
902+
873903
/**
874904
* Assert that the given text is present in the HTML email body.
875905
*

src/Illuminate/Notifications/Messages/MailMessage.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Illuminate\Contracts\Support\Renderable;
88
use Illuminate\Mail\Markdown;
99
use Illuminate\Support\Traits\Conditionable;
10+
use Symfony\Component\Mailer\Header\MetadataHeader;
11+
use Symfony\Component\Mailer\Header\TagHeader;
12+
use Symfony\Component\Mime\Email;
1013

1114
class MailMessage extends SimpleMessage implements Renderable
1215
{
@@ -253,6 +256,33 @@ public function attachData($data, $name, array $options = [])
253256
return $this;
254257
}
255258

259+
/**
260+
* Add a tag header to the message when supported by the underlying transport.
261+
*
262+
* @param string $value
263+
* @return $this
264+
*/
265+
public function tag($value)
266+
{
267+
return $this->withSymfonyMessage(function (Email $message) use ($value) {
268+
$message->getHeaders()->add(new TagHeader($value));
269+
});
270+
}
271+
272+
/**
273+
* Add a metadata header to the message when supported by the underlying transport.
274+
*
275+
* @param string $key
276+
* @param string $value
277+
* @return $this
278+
*/
279+
public function metadata($key, $value)
280+
{
281+
return $this->withSymfonyMessage(function (Email $message) use ($key, $value) {
282+
$message->getHeaders()->add(new MetadataHeader($key, $value));
283+
});
284+
}
285+
256286
/**
257287
* Set the priority of this message.
258288
*

0 commit comments

Comments
 (0)