Skip to content

Instantly share code, notes, and snippets.

@drakakisgeo
Last active April 9, 2019 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drakakisgeo/1bd4ca1bf9742b026d62622882c2e72b to your computer and use it in GitHub Desktop.
Save drakakisgeo/1bd4ca1bf9742b026d62622882c2e72b to your computer and use it in GitHub Desktop.
Postmark Trait for Laravel Mailable - (Support for Tag and Meta)
<?php
namespace App\Billit\Traits;
trait Postmarkable
{
/**
* @param array $tags
*/
public function setTag(string $tag): void
{
$this->tag = $tag;
}
/**
* @param array $meta
*/
public function setMeta(array $meta): void
{
$this->meta = $meta;
}
private function addPostmarkHeaders()
{
if ($this->tag || sizeof($this->meta) > 0) {
$this->withSwiftMessage(function ($message) {
if ($this->tag) {
$message->getHeaders()->addTextHeader('X-PM-Tag', $this->tag);
}
if (sizeof($this->meta) > 0) {
foreach ($this->meta as $key=>$value) {
$message->getHeaders()->addTextHeader('X-PM-Metadata-'.$key, $value);
}
}
});
}
return $this;
}
}
<?php
namespace App\Billit\Traits;
trait Postmarkable
{
/**
* @param array $tags
*/
public function setTag(array $tag): void
{
$this->tag = $tag;
}
/**
* @param array $meta
*/
public function setMeta(array $meta): void
{
$this->meta = $meta;
}
private function addPostmarkHeaders()
{
if ($this->tag || sizeof($this->meta) > 0) {
$this->withSwiftMessage(function ($message) {
if ($this->tag) {
$message->getHeaders()->addTextHeader('X-PM-Tag', $this->tag);
}
if (sizeof($this->meta) > 0) {
foreach ($this->meta as $key=>$value) {
$message->getHeaders()->addTextHeader('X-PM-Metadata-'.$key, $value);
}
}
});
}
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment