diff --git a/changelog.md b/changelog.md index c83c9416..0ff5c2fd 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # ChangeLog +* Add custom header getter * Use `application/javascript` for .js attachments * Improve RFC2821 compliance for timelimits, especially for end-of-data * Add Azerbaijani translations (Thanks to @mirjalal) diff --git a/class.phpmailer.php b/class.phpmailer.php index 55795898..ac723028 100644 --- a/class.phpmailer.php +++ b/class.phpmailer.php @@ -2952,6 +2952,16 @@ class PHPMailer } } + /** + * Returns all custom headers + * + * @return array + */ + public function getCustomHeaders() + { + return $this->CustomHeader; + } + /** * Create a message from an HTML string. * Automatically makes modifications for inline images and backgrounds diff --git a/test/phpmailerTest.php b/test/phpmailerTest.php index 2f871fa5..f1037a3d 100644 --- a/test/phpmailerTest.php +++ b/test/phpmailerTest.php @@ -1680,6 +1680,33 @@ EOT; 'SMTP connect with options failed' ); } + + /** + * Tests the Custom header getter + */ + public function testCustomHeaderGetter() + { + $this->Mail->addCustomHeader('foo', 'bar'); + $this->assertEquals(array(array('foo', 'bar')), $this->Mail->getCustomHeaders()); + + $this->Mail->addCustomHeader('foo', 'baz'); + $this->assertEquals(array( + array('foo', 'bar'), + array('foo', 'baz') + ), $this->Mail->getCustomHeaders()); + + $this->Mail->clearCustomHeaders(); + $this->assertEmpty($this->Mail->getCustomHeaders()); + + $this->Mail->addCustomHeader('yux'); + $this->assertEquals(array(array('yux')), $this->Mail->getCustomHeaders()); + + $this->Mail->addCustomHeader('Content-Type: application/json'); + $this->assertEquals(array( + array('yux'), + array('Content-Type', ' application/json') + ), $this->Mail->getCustomHeaders()); + } } /**