Skip to content

Commit

Permalink
Merge pull request #16 from railsware/feature/improvements-2023-10
Browse files Browse the repository at this point in the history
Support 'reply-to' header
  • Loading branch information
gaalferov authored Oct 13, 2023
2 parents 8426e9b + fdbabc6 commit cc6e91f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ $mailtrap = new MailtrapClient(new Config($apiKey));

$email = (new Email())
->from(new Address('[email protected]', 'Mailtrap Test'))
->replyTo(new Address('[email protected]'))
->to(new Address('[email protected]', 'Jon'))
->priority(Email::PRIORITY_HIGH)
->cc('[email protected]')
->addCc('[email protected]')
->bcc('[email protected]')
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"php-http/client-common": "^2.0",
"php-http/httplug": "^2.0",
"php-http/discovery": "^1.0",
"php-http/message-factory": "^1.0",
"symfony/mime": "^5.4|^6.0",
"egulias/email-validator": "^2.1.10|^3.1|^4"
},
Expand Down
1 change: 1 addition & 0 deletions examples/sandbox/emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

$email = (new Email())
->from(new Address('[email protected]', 'Mailtrap Test'))
->replyTo(new Address('[email protected]'))
->to(new Address('[email protected]', 'Jon'))
->cc('[email protected]')
->addCc('[email protected]')
Expand Down
3 changes: 3 additions & 0 deletions examples/sending/emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

$email = (new Email())
->from(new Address('[email protected]', 'Mailtrap Test')) // <--- you should use your domain here that you installed in the mailtrap.io admin area (otherwise you will get 401)
->replyTo(new Address('[email protected]'))
->to(new Address('[email protected]', 'Jon'))
->priority(Email::PRIORITY_HIGH)
->cc('[email protected]')
->addCc('[email protected]')
->bcc('[email protected]')
Expand Down Expand Up @@ -91,6 +93,7 @@

$email = (new Email())
->from(new Address('[email protected]', 'Mailtrap Test')) // <--- you should use your domain here that you installed in the mailtrap.io admin area (otherwise you will get 401)
->replyTo(new Address('[email protected]'))
->to(new Address('[email protected]', 'Jon'))
;

Expand Down
2 changes: 1 addition & 1 deletion src/Api/AbstractEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function getPayload(Email $email): array
$payload['attachments'] = $this->getAttachments($email);
}

$headersToBypass = ['received', 'from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'reply-to'];
$headersToBypass = ['received', 'from', 'to', 'cc', 'bcc', 'subject', 'content-type'];
foreach ($email->getHeaders()->all() as $name => $header) {
if (in_array($name, $headersToBypass, true)) {
continue;
Expand Down
6 changes: 5 additions & 1 deletion tests/Api/Sandbox/EmailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function testValidSendToSandBox(): void

$email = new Email();
$email->from(new Address('[email protected]', 'Ms. Foo Bar'))
->replyTo(new Address('[email protected]'))
->to(new Address('[email protected]', 'Mr. Recipient'))
->priority(Email::PRIORITY_HIGH)
->bcc('[email protected]')
->subject('Best practices of building HTML emails')
->text('Some text')
Expand Down Expand Up @@ -82,7 +84,9 @@ public function testValidSendToSandBox(): void
'text' => 'Some text',
'html' => '<p>Some text</p>',
'headers' => [
'X-Message-Source' => 'dev.mydomain.com'
'X-Message-Source' => 'dev.mydomain.com',
'Reply-To' => '[email protected]',
'X-Priority' => '2 (High)',
]
])
->willReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode($expectedData)));
Expand Down
6 changes: 5 additions & 1 deletion tests/Api/Sending/EmailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public function testValidSend(): void

$email = new Email();
$email->from(new Address('[email protected]', 'Ms. Foo Bar'))
->replyTo(new Address('[email protected]'))
->to(new Address('[email protected]', 'Mr. Recipient'))
->priority(Email::PRIORITY_HIGH)
->bcc('[email protected]')
->subject('Best practices of building HTML emails')
->text('Some text')
Expand Down Expand Up @@ -87,7 +89,9 @@ public function testValidSend(): void
'text' => 'Some text',
'html' => '<p>Some text</p>',
'headers' => [
'X-Message-Source' => 'dev.mydomain.com'
'X-Message-Source' => 'dev.mydomain.com',
'Reply-To' => '[email protected]',
'X-Priority' => '2 (High)',
]
])
->willReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode($expectedData)));
Expand Down

0 comments on commit cc6e91f

Please sign in to comment.