From 6ad776554195d64a635a5a4930109035953e42a4 Mon Sep 17 00:00:00 2001 From: Vladimir Voronin Date: Tue, 6 Dec 2016 19:04:49 +0300 Subject: [PATCH] add support headers in mail message --- Message.php | 7 +++++++ libs/SimpleEmailServiceMessage.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Message.php b/Message.php index 4d6f949..30d8ad0 100644 --- a/Message.php +++ b/Message.php @@ -347,4 +347,11 @@ public function getHeaders() //todo: make headers for debug return ''; } + + public function setHeader($key, $value) + { + $this->getSesMessage()->addTextHeader($key, $value); + + return $this; + } } \ No newline at end of file diff --git a/libs/SimpleEmailServiceMessage.php b/libs/SimpleEmailServiceMessage.php index 42cbc06..b70cae5 100644 --- a/libs/SimpleEmailServiceMessage.php +++ b/libs/SimpleEmailServiceMessage.php @@ -18,6 +18,7 @@ final class SimpleEmailServiceMessage { public $subject, $messagetext, $messagehtml; public $subjectCharset, $messageTextCharset, $messageHtmlCharset; public $attachments = array(); + public $headers = []; function __construct() { $this->to = array(); @@ -35,6 +36,8 @@ function __construct() { $this->subjectCharset = null; $this->messageTextCharset = null; $this->messageHtmlCharset = null; + + $this->headers = []; } @@ -79,6 +82,14 @@ function addReplyTo($replyto) { } } + function addTextHeader($key, $value) { + if (!$key) { + return; + } + + $this->headers[] = [$key => $value]; + } + function setFrom($from) { $this->from = $from; } @@ -198,6 +209,13 @@ function getRawMessage() $raw_message .= 'Subject: =?' . $this->subjectCharset . '?B?' . base64_encode($this->subject) . '?=' . "\n"; } } + + foreach ($this->headers as &$header) { + foreach ($header as $key => $value) { + $raw_message .= $key . ': ' . $value . "\n"; + } + } + $raw_message .= 'MIME-Version: 1.0' . "\n"; $raw_message .= 'Content-type: Multipart/Mixed; boundary="' . $boundary . '"' . "\n"; $raw_message .= "\n--{$boundary}\n";