diff --git a/src/Postmark/PostmarkClient.php b/src/Postmark/PostmarkClient.php index 53652d51..1e085244 100644 --- a/src/Postmark/PostmarkClient.php +++ b/src/Postmark/PostmarkClient.php @@ -129,6 +129,8 @@ public function sendEmail( */ public function sendEmailModel(PostmarkMessage $postmarkMessage): PostmarkResponse { + $headers = $this->fixHeaders($postmarkMessage->getHeaders()); + $postmarkMessage->setHeaders($headers); return new PostmarkResponse((array) $this->processRestRequest('POST', '/email', (array) $postmarkMessage)); } @@ -277,6 +279,8 @@ public function sendEmailWithTemplate( public function sendEmailWithTemplateModel(TemplatedPostmarkMessage $postmarkMessageTemplate): PostmarkResponse { + $headers = $this->fixHeaders($postmarkMessageTemplate->getHeaders()); + $postmarkMessageTemplate->setHeaders($headers); return new PostmarkResponse((array) $this->processRestRequest('POST', '/email/withTemplate', (array) $postmarkMessageTemplate)); } diff --git a/tests/PostmarkClientEmailTest.php b/tests/PostmarkClientEmailTest.php index 9d06cb63..ad676d3b 100644 --- a/tests/PostmarkClientEmailTest.php +++ b/tests/PostmarkClientEmailTest.php @@ -106,9 +106,10 @@ public function testClientSendModel() $emailModel->setFrom($tk->WRITE_TEST_SENDER_EMAIL_ADDRESS); $emailModel->setTo($tk->WRITE_TEST_EMAIL_RECIPIENT_ADDRESS); $emailModel->setSubject("Hello from the PHP Postmark Client Tests! ({$currentTime})"); - $emailModel->setHtmlBody('Hi there!'); - $emailModel->setTextBody('This is a text body for a test email.'); + $emailModel->setHtmlBody('Hi there! sent via a model.'); + $emailModel->setTextBody('This is a text body for a test email sent via a model.'); $emailModel->setMessageStream('outbound'); + $emailModel->setHeaders(['X-Test-Header' => 'Header.', 'X-Test-Header-2' => 'Test Header 2']); $response = $client->sendEmailModel($emailModel); diff --git a/tests/PostmarkClientTemplatesTest.php b/tests/PostmarkClientTemplatesTest.php index 68fed1f1..0510542c 100644 --- a/tests/PostmarkClientTemplatesTest.php +++ b/tests/PostmarkClientTemplatesTest.php @@ -176,13 +176,14 @@ public function testClientCanSendMailWithTemplateModel() { $tk = parent::$testKeys; $client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT); - $result = $client->createTemplate('test-php-template-' . date('c'), '{{subject}}', 'Hello {{name}}!', 'Hello {{name}}!'); + $result = $client->createTemplate('test-php-template-' . date('c'), '{{subject}}', 'Hello {{name}} from Template Model!', 'Hello {{name}} from Template Model!'); $templatedModel = new TemplatedPostmarkMessage(); $templatedModel->setFrom($tk->WRITE_TEST_SENDER_EMAIL_ADDRESS); $templatedModel->setTo($tk->WRITE_TEST_EMAIL_RECIPIENT_ADDRESS); $templatedModel->setTemplateId($result->getTemplateId()); $templatedModel->setTemplateModel(['subjectValue' => 'Hello!']); + $templatedModel->setHeaders(['X-Test-Header' => 'Header.', 'X-Test-Header-2' => 'Test Header 2']); $emailResult = $client->sendEmailWithTemplateModel($templatedModel);