Skip to content

Commit

Permalink
Merge pull request #35 from narendravaghela/3.x-fixsender
Browse files Browse the repository at this point in the history
Adding sender header and fixing var names
  • Loading branch information
challgren authored Mar 31, 2020
2 parents ce3dc0f + 002a0de commit 7e657d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/composer.lock
/phpunit.xml
/vendor
/.phpunit.result.cache
/clover.xml
4 changes: 4 additions & 0 deletions src/Mailer/Transport/MailgunTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ protected function _prepareEmailAddresses(Email $email)
$this->_formData->add('from', sprintf("%s <%s>", key($from), key($from)));
}

foreach ($email->getSender() as $senderEmail => $senderName) {
$this->_formData->add('h:Sender', sprintf("%s <%s>", $senderName, $senderEmail));
}

foreach ($email->getTo() as $toEmail => $toName) {
$this->_formData->add('to', sprintf("%s <%s>", $toName, $toEmail));
}
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/Mailer/Transport/MailgunTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function testAdditionalEmailAddresses()
->addCC(['[email protected]', '[email protected]' => 'John'])
->addBcc(['[email protected]', '[email protected]' => 'John'])
->setReplyTo(['[email protected]' => 'John'])
->setSender(['[email protected]' => 'John'])
->setEmailFormat('both')
->setSubject('Email from CakePHP Mailgun plugin')
->send('Hello there, <br> This is an email from CakePHP Mailgun Email plugin.');
Expand All @@ -101,13 +102,15 @@ public function testAdditionalEmailAddresses()
$this->assertTextContains('Content-Disposition: form-data; name="cc"', $reqDataString);
$this->assertTextContains('Content-Disposition: form-data; name="bcc"', $reqDataString);
$this->assertTextContains('Content-Disposition: form-data; name="h:Reply-To"', $reqDataString);
$this->assertTextContains('Content-Disposition: form-data; name="h:Sender"', $reqDataString);
$this->assertTextContains('[email protected] <[email protected]>', $reqDataString);
$this->assertTextContains('[email protected] <[email protected]>', $reqDataString);
$this->assertTextContains('[email protected] <[email protected]>', $reqDataString);
$this->assertTextContains('John <[email protected]>', $reqDataString);
$this->assertTextContains('[email protected] <[email protected]>', $reqDataString);
$this->assertTextContains('John <[email protected]>', $reqDataString);
$this->assertTextContains('John <[email protected]>', $reqDataString);
$this->assertTextContains('John <[email protected]>', $reqDataString);
}

public function testCustomHeaders()
Expand Down

0 comments on commit 7e657d8

Please sign in to comment.