Problem/Motivation

When a user doesn't enter anything in CC and BCC fields in the Test email form, then it throws the below error:

Drupal\Core\Entity\EntityStorageException: Invalid address: (cc): in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 846 of /var/www/d8/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
    

PHPMailer\PHPMailer\Exception: Invalid address: (cc): in PHPMailer\PHPMailer\PHPMailer->addOrEnqueueAnAddress() (line 1081 of /var/www/d8/vendor/phpmailer/phpmailer/src/PHPMailer.php).

Steps to reproduce

  1. Enable the Reroute EMail module.
  2. Navigate to the Test Email Form.
  3. Enter the To email address as it's mandatory field and keep the cc & bcc fields as is.
  4. Submit the form and you will get The website encountered an unexpected error. issue.

The reason it sends empty CC and BCC values but SMTP/PHPMailer modules expect headers which has both key & value.

Array
(
    [cc] => 
    [bcc] => 
    [subject] => Reroute Email Test
    [body] => Reroute Email Body
)

Proposed resolution

Need to unset the keys which have empty values. For example: in the above case, CC & BCC should not be part of the params array, if empty.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

er.pushpinderrana created an issue. See original summary.

pushpinderchauhan’s picture

Status: Needs review » Needs work

The last submitted patch, 2: test-email-form-invalid-address-cc-3174784-2.patch, failed testing. View results

pushpinderchauhan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.72 KB
new3.15 KB

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed the patch, and can confirm this resolves the issue.

It adds tests coverage too

Great work @er.pushpinderrana

kleiton_rodrigues’s picture

StatusFileSize
new37 KB
new61.67 KB

The patch #5 has been applied cleanly
good for me
RTBC+1

patch_applied

Only local images are allowed.

bohart made their first commit to this issue’s fork.

  • bohart committed 4b1b100 on 2.x
    Issue #3174784 by er.pushpinderrana, bohart: Fixed fatal error due to...
bohart’s picture

Title: Test email form - Invalid address: (cc): PHPMailer » Test email form - Invalid address: (cc): PHPMailer\Exception
Version: 8.x-1.x-dev » 2.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: +LutskCodeSprint2021

@er.pushpinderrana, @kleiton_rodrigues, @larowlan, thanks for your contribution!

All the changes are committed to both 8.x-1.x-dev and 2.x-dev branches now.
So the fix will be included in the next module versions.

In the meantime, a few additional test coverage changes have been added also (to test cc/bcc values/headers for all tests).
Marking this issue as fixed now, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.