Commit 66d6d1d1 authored by Pushpinder Chauhan's avatar Pushpinder Chauhan Committed by Jakob P
Browse files

Issue #3174535 by er.pushpinderrana, TR, Andrew Answer: Invalid address: (cc): PHPMailer Issue

parent 79802dbb
Loading
Loading
Loading
Loading
+6 −0
Changes for src/Plugin/Mail/SMTPMailSystem.php: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -318,6 +318,12 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
    // Parse the headers of the message and set the PHPMailer object's settings
    // accordingly.
    foreach ($headers as $key => $value) {
      if ($value == NULL || $value == '') {
        // $value should always be set. If not, remove the header field and
        // skip to the next header field.
        unset($headers[$key]);
        continue;
      }
      switch ($key) {
        case 'from':
          if ($from == NULL or $from == '') {
+37 −0
Changes for tests/src/Unit/Plugin/Mail/SMTPMailSystemTest.php: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -277,6 +277,43 @@ class SMTPMailSystemTest extends UnitTestCase {
    self::assertTrue($result);
  }

  /**
   * Test mail() with missing header value.
   */
  public function testMailHeader() {
    $mailSystem = new SMTPMailSystemTestHelper(
      [],
      '',
      [],
      $this->mockLogger->reveal(),
      $this->mockMessenger->reveal(),
      new EmailValidatorPhpMailerDefault(),
      $this->mockConfigFactory,
      $this->mockCurrentUser->reveal(),
      $this->mockFileSystem->reveal(),
      $this->mimeTypeGuesser->reveal()
    );

    $message = [
      'to' => 'test@drupal.org',
      'from' => 'PhpUnit Localhost <phpunit@localhost.com>',
      'body' => 'Some test content for testMailHeaderDrupal',
      'headers' => [
        'content-type' => 'text/plain',
        'from' => 'test@drupal.org',
        'reply-to' => 'test@drupal.org',
        'cc' => '',
        'bcc' => '',
      ],
      'subject' => 'testMailHeaderDrupal',
    ];

    // Call function.
    $result = $mailSystem->mail($message);

    self::assertTrue($result);
  }

}

/**