From 39bdca38a07b84a0c177bbd810d6903a13b4571c Mon Sep 17 00:00:00 2001 From: gaalferov Date: Thu, 12 Oct 2023 11:46:33 +0200 Subject: [PATCH 1/2] add the required library for PHP 7.4 --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 5c2d26a..efefb68 100644 --- a/composer.json +++ b/composer.json @@ -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" }, From fdbabc6617bc0f267caa04aa63133624d705fef2 Mon Sep 17 00:00:00 2001 From: gaalferov Date: Thu, 12 Oct 2023 12:40:25 +0200 Subject: [PATCH 2/2] support 'reply-to' mail header --- README.md | 2 ++ examples/sandbox/emails.php | 1 + examples/sending/emails.php | 3 +++ src/Api/AbstractEmails.php | 2 +- tests/Api/Sandbox/EmailsTest.php | 6 +++++- tests/Api/Sending/EmailsTest.php | 6 +++++- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 432f792..29d2158 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ $mailtrap = new MailtrapClient(new Config($apiKey)); $email = (new Email()) ->from(new Address('example@your-domain-here.com', 'Mailtrap Test')) + ->replyTo(new Address('reply@your-domain-here.com')) ->to(new Address('email@example.com', 'Jon')) + ->priority(Email::PRIORITY_HIGH) ->cc('mailtrapqa@example.com') ->addCc('staging@example.com') ->bcc('mailtrapdev@example.com') diff --git a/examples/sandbox/emails.php b/examples/sandbox/emails.php index c0da33c..e0d8110 100644 --- a/examples/sandbox/emails.php +++ b/examples/sandbox/emails.php @@ -29,6 +29,7 @@ $email = (new Email()) ->from(new Address('mailtrap@example.com', 'Mailtrap Test')) + ->replyTo(new Address('reply@example.com')) ->to(new Address('email@example.com', 'Jon')) ->cc('mailtrapqa@example.com') ->addCc('staging@example.com') diff --git a/examples/sending/emails.php b/examples/sending/emails.php index b1d10b7..7c4b5f2 100644 --- a/examples/sending/emails.php +++ b/examples/sending/emails.php @@ -31,7 +31,9 @@ $email = (new Email()) ->from(new Address('example@YOUR-DOMAIN-HERE.com', '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('reply@YOUR-DOMAIN-HERE.com')) ->to(new Address('email@example.com', 'Jon')) + ->priority(Email::PRIORITY_HIGH) ->cc('mailtrapqa@example.com') ->addCc('staging@example.com') ->bcc('mailtrapdev@example.com') @@ -91,6 +93,7 @@ $email = (new Email()) ->from(new Address('example@YOUR-DOMAIN-HERE.com', '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('reply@YOUR-DOMAIN-HERE.com')) ->to(new Address('example@gmail.com', 'Jon')) ; diff --git a/src/Api/AbstractEmails.php b/src/Api/AbstractEmails.php index 93cae94..02f5d60 100644 --- a/src/Api/AbstractEmails.php +++ b/src/Api/AbstractEmails.php @@ -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; diff --git a/tests/Api/Sandbox/EmailsTest.php b/tests/Api/Sandbox/EmailsTest.php index efa0a26..e331ed9 100644 --- a/tests/Api/Sandbox/EmailsTest.php +++ b/tests/Api/Sandbox/EmailsTest.php @@ -54,7 +54,9 @@ public function testValidSendToSandBox(): void $email = new Email(); $email->from(new Address('foo@example.com', 'Ms. Foo Bar')) + ->replyTo(new Address('reply@example.com')) ->to(new Address('bar@example.com', 'Mr. Recipient')) + ->priority(Email::PRIORITY_HIGH) ->bcc('baz@example.com') ->subject('Best practices of building HTML emails') ->text('Some text') @@ -82,7 +84,9 @@ public function testValidSendToSandBox(): void 'text' => 'Some text', 'html' => '

Some text

', 'headers' => [ - 'X-Message-Source' => 'dev.mydomain.com' + 'X-Message-Source' => 'dev.mydomain.com', + 'Reply-To' => 'reply@example.com', + 'X-Priority' => '2 (High)', ] ]) ->willReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode($expectedData))); diff --git a/tests/Api/Sending/EmailsTest.php b/tests/Api/Sending/EmailsTest.php index 0e70cc1..352e380 100644 --- a/tests/Api/Sending/EmailsTest.php +++ b/tests/Api/Sending/EmailsTest.php @@ -59,7 +59,9 @@ public function testValidSend(): void $email = new Email(); $email->from(new Address('foo@example.com', 'Ms. Foo Bar')) + ->replyTo(new Address('reply@example.com')) ->to(new Address('bar@example.com', 'Mr. Recipient')) + ->priority(Email::PRIORITY_HIGH) ->bcc('baz@example.com') ->subject('Best practices of building HTML emails') ->text('Some text') @@ -87,7 +89,9 @@ public function testValidSend(): void 'text' => 'Some text', 'html' => '

Some text

', 'headers' => [ - 'X-Message-Source' => 'dev.mydomain.com' + 'X-Message-Source' => 'dev.mydomain.com', + 'Reply-To' => 'reply@example.com', + 'X-Priority' => '2 (High)', ] ]) ->willReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode($expectedData)));