Skip to content

Commit

Permalink
Fixer (#120)
Browse files Browse the repository at this point in the history
Fix to address #119

---------

Co-authored-by: Eli Wood <[email protected]>
  • Loading branch information
ewood-ac and Eli Wood authored Dec 11, 2023
1 parent 7fd9d8e commit c6bbc44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Postmark/PostmarkClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand Down
5 changes: 3 additions & 2 deletions tests/PostmarkClientEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<b>Hi there!</b>');
$emailModel->setTextBody('This is a text body for a test email.');
$emailModel->setHtmlBody('<b>Hi there! sent via a model.</b>');
$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);

Expand Down
3 changes: 2 additions & 1 deletion tests/PostmarkClientTemplatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>{{name}}</b>!', 'Hello {{name}}!');
$result = $client->createTemplate('test-php-template-' . date('c'), '{{subject}}', 'Hello <b>{{name}}</b> 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);

Expand Down

0 comments on commit c6bbc44

Please sign in to comment.