From 957b0eb96e32e3a723f94a74b2d34f693e399aa3 Mon Sep 17 00:00:00 2001 From: Lenny ROUANET Date: Wed, 27 Mar 2024 09:37:08 +0100 Subject: [PATCH] Email : Add cc and bcc --- component/Web/Email.php | 4 ++++ test/Web/EmailTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/component/Web/Email.php b/component/Web/Email.php index 241b0b5..5553bc6 100644 --- a/component/Web/Email.php +++ b/component/Web/Email.php @@ -15,6 +15,8 @@ final public function __construct( public string $messageHtml, public EmailAddressAndName $from, public EmailAddressAndNameList $to, + public ?EmailAddressAndNameList $cc, + public ?EmailAddressAndNameList $bcc, public ?EmailAddressAndName $replyTo = null, public ?EmailAttachmentList $attachmentList = null ) { @@ -46,6 +48,8 @@ public static function make( $toName ) ), + null, + null, $replyToEmailAddress ? EmailAddressAndName::make( $replyToEmailAddress, $replyToName diff --git a/test/Web/EmailTest.php b/test/Web/EmailTest.php index f850bc2..75eb672 100644 --- a/test/Web/EmailTest.php +++ b/test/Web/EmailTest.php @@ -46,6 +46,18 @@ public function testInterface(): void 'John DOE' ) ), + (new EmailAddressAndNameList())->add( + new EmailAddressAndName( + new EmailAddress('john.doe@domain.ext'), + 'John DOE' + ) + ), + (new EmailAddressAndNameList())->add( + new EmailAddressAndName( + new EmailAddress('john.doe@domain.ext'), + 'John DOE' + ) + ), new EmailAddressAndName( new EmailAddress('no-reply@acme.ext'), 'No reply' @@ -73,6 +85,18 @@ public function testInterface(): void $this->assertEquals('john.doe@domain.ext', (string)$to->emailAddress); $this->assertEquals('John DOE', $to->name); + $this->assertIsObject($email->cc); + $this->assertInstanceOf(EmailAddressAndNameList::class, $email->cc); + $cc = $email->cc->itemsIterator()->current(); + $this->assertEquals('john.doe@domain.ext', (string)$cc->emailAddress); + $this->assertEquals('John DOE', $cc->name); + + $this->assertIsObject($email->bcc); + $this->assertInstanceOf(EmailAddressAndNameList::class, $email->bcc); + $bcc = $email->bcc->itemsIterator()->current(); + $this->assertEquals('john.doe@domain.ext', (string)$bcc->emailAddress); + $this->assertEquals('John DOE', $bcc->name); + $this->assertIsObject($email->replyTo); $this->assertInstanceOf(EmailAddressAndName::class, $email->replyTo); $this->assertEquals('no-reply@acme.ext', (string)$email->replyTo->emailAddress);