diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index 3e8cf6b45577..27f5b0fe155b 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -20,6 +20,9 @@ use PHPUnit\Framework\Assert as PHPUnit; use ReflectionClass; use ReflectionProperty; +use Symfony\Component\Mailer\Header\MetadataHeader; +use Symfony\Component\Mailer\Header\TagHeader; +use Symfony\Component\Mime\Email; class Mailable implements MailableContract, Renderable { @@ -870,6 +873,33 @@ public function attachData($data, $name, array $options = []) return $this; } + /** + * Add a tag header to the message when supported by the underlying transport. + * + * @param string $value + * @return $this + */ + public function tag($value) + { + return $this->withSymfonyMessage(function (Email $message) use ($value) { + $message->getHeaders()->add(new TagHeader($value)); + }); + } + + /** + * Add a metadata header to the message when supported by the underlying transport. + * + * @param string $key + * @param string $value + * @return $this + */ + public function metadata($key, $value) + { + return $this->withSymfonyMessage(function (Email $message) use ($key, $value) { + $message->getHeaders()->add(new MetadataHeader($key, $value)); + }); + } + /** * Assert that the given text is present in the HTML email body. * diff --git a/src/Illuminate/Notifications/Messages/MailMessage.php b/src/Illuminate/Notifications/Messages/MailMessage.php index 24c2515ca52c..da4a6a678627 100644 --- a/src/Illuminate/Notifications/Messages/MailMessage.php +++ b/src/Illuminate/Notifications/Messages/MailMessage.php @@ -7,6 +7,9 @@ use Illuminate\Contracts\Support\Renderable; use Illuminate\Mail\Markdown; use Illuminate\Support\Traits\Conditionable; +use Symfony\Component\Mailer\Header\MetadataHeader; +use Symfony\Component\Mailer\Header\TagHeader; +use Symfony\Component\Mime\Email; class MailMessage extends SimpleMessage implements Renderable { @@ -253,6 +256,33 @@ public function attachData($data, $name, array $options = []) return $this; } + /** + * Add a tag header to the message when supported by the underlying transport. + * + * @param string $value + * @return $this + */ + public function tag($value) + { + return $this->withSymfonyMessage(function (Email $message) use ($value) { + $message->getHeaders()->add(new TagHeader($value)); + }); + } + + /** + * Add a metadata header to the message when supported by the underlying transport. + * + * @param string $key + * @param string $value + * @return $this + */ + public function metadata($key, $value) + { + return $this->withSymfonyMessage(function (Email $message) use ($key, $value) { + $message->getHeaders()->add(new MetadataHeader($key, $value)); + }); + } + /** * Set the priority of this message. *