Problem/Motivation

Steps to reproduce

When a webform email handler has cc_mail or bcc_mail left blank (either null or ''), a watchdog error is logged on every form submission:

Web Request Form: The 'bcc_mail' email () is not valid for 'Email' and it has been removed. Please check webform settings.

The email is still sent correctly — the error is a false positive. But it pollutes watchdog with errors on every submission.

Steps to reproduce

1. Create a webform with an email handler
2. Leave the CC and/or BCC fields blank in the handler settings
3. Submit the form
4. Check watchdog — error is logged for each empty CC/BCC field

Root cause

In EmailWebformHandler::getMessage(), every configuration key is iterated and written to $message. For cc_mail with a value of null or '', the processing pipeline in
getMessageEmails() correctly returns an empty array, and implode() converts that to ''. So $message['cc_mail'] ends up set to ''.

Later in sendMessage() (line 1208), the validation check uses isset():

if (isset($message['cc_mail'])) {
$address_to_validate['cc_mail'] = $message['cc_mail'];
}

isset('') returns true, so the empty string is passed to Address::create('') which throws an exception and triggers the error log.

Proposed resolution

Change isset() to !empty() for the cc and bcc checks:

  if (!empty($message['cc_mail'])) {
      $address_to_validate['cc_mail'] = $message['cc_mail'];
  }
  if (!empty($message['bcc_mail'])) {
      $address_to_validate['bcc_mail'] = $message['bcc_mail'];
  }
--- a/src/Plugin/WebformHandler/EmailWebformHandler.php
  +++ b/src/Plugin/WebformHandler/EmailWebformHandler.php
  @@ -1205,10 +1205,10 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
       $address_to_validate = [
         'from' => $from,
       ];
  -    if (isset($message['cc_mail'])) {
  +    if (!empty($message['cc_mail'])) {
         $address_to_validate['cc_mail'] = $message['cc_mail'];
       }
  -    if (isset($message['bcc_mail'])) {
  +    if (!empty($message['bcc_mail'])) {
         $address_to_validate['bcc_mail'] = $message['bcc_mail'];
       }

Issue fork webform-3603017

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

kcolwell created an issue. See original summary.

kcolwell’s picture

Issue summary: View changes

pjovanovic’s picture

Assigned: Unassigned » pjovanovic
pjovanovic’s picture

I am not sure that I can follow this problem.
The code you mentioned if (isset($message['cc_mail'])) { does not exist in the 6.3.x branch.
I also couldn't find this code on the branch of your fork.
As far as I can see, this is already handled on the following line:
src/Plugin/WebformHandler/EmailWebformHandler.php:1306

Or maybe I am missing something.

pjovanovic’s picture

Assigned: pjovanovic » Unassigned
liam morland’s picture

Version: 6.3.0-rc1 » 6.3.x-dev
Status: Active » Postponed (maintainer needs more info)

It looks like you may be running a modified version of Webform. Please update the issue summery to refer to Webform code as it comes from this project.

liam morland’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.