If you attempt you send an email with either CC or BCC and it's not in the form of name <email address>, the following error is generated:

Notice: Undefined offset: 1 in Drupal\sendgrid_integration\Plugin\Mail\SendGridMail->mail() (line 429 of sendgrid_integration/src/Plugin/Mail/SendGridMail.php

Lines 429-433 contains the following code:

[$mail_cc_address, $cc_name] = $this->parseAddress($mail_id);
$address_cc_bcc[mb_strtolower($key)][] = [
  'mail' => $mail_cc_address,
  'name' => $cc_name,
];
CommentFileSizeAuthor
#4 3231561_4.patch934 bytesanas_maw
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

intrafusion created an issue. See original summary.

kevinhbruce’s picture

I'm running into the same issue with Drupal Commerce's use of sendgrid integration

kevinhbruce’s picture

I was able to quiet the message by taking that code and replacing it with the following:

$email_components = $this->parseAddress($mail_id);
$mail_cc_address = $email_components[0];
//if there was a name with the mail, use it—otherwise, use the email address as the name
$cc_name = $email_components[1] ?? $email_components[0];
$address_cc_bcc[mb_strtolower($key)][] = [
    'mail' => $mail_cc_address,
    'name' => $cc_name,
];
anas_maw’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new934 bytes

Running to the same problem, code in #3 solved my issue
I just make a patch for the code in #3

intrafusion’s picture

Status: Reviewed & tested by the community » Needs review

Thanks for the patch, but you cannot review your own patch

anas_maw’s picture

Thanks for your note, I reviewed the code in #3, and just created a patch for it.
Anyway, please review it and move it to RTCB as this will cause the whole email to fail if there is a CC or BCC with a capital case

metafoo’s picture

Patch #4 is broken.

Fixes error getting flagged, but functionality is still broken.

If item contains both cc and bcc, the cc is clobbered by re-initialising array $address_cc_bcc, thus will not send the cc.

Removing the line

 $address_cc_bcc = [];

fixes. Just let the array get initialised when its first used.

      $address_cc_bcc = [];

      // Handle latter case issue for cc and bcc key.
      if (in_array(mb_strtolower($key), $cc_bcc_keys)) {
        $mail_ids = explode(',', $value);
        foreach ($mail_ids as $mail_id) {
          $email_components = $this->parseAddress($mail_id);
          $mail_cc_address = $email_components[0];
          // If there was a name with the mail,
          // use it—otherwise, use the email address as the name.
          $cc_name = $email_components[1] ?? $email_components[0];
          $address_cc_bcc[mb_strtolower($key)][] = [
            'mail' => $mail_cc_address,
            'name' => $cc_name,
          ];
        }

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

parisek’s picture

Priority: Normal » Major

Created MR from attached patch and fixed #7

Changed to major as if both CC and BCC recepients are set, only later one is sent.

perignon’s picture

Status: Needs review » Fixed

PR merged. Thanks!

Status: Fixed » Closed (fixed)

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

intrafusion’s picture