When sending an HTML mail from Rules, I am now getting the notice "Undefined index: Reply-To in SendGridMailSystem->mail()" - interesting thing is that I am provided a reply-to value in the rule itself, which makes me think maybe there is something wrong with the way the rules action is integrating with the SendGridMailSystem class?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lionguard created an issue. See original summary.

Perignon’s picture

Hrm. I will add this to the stack of things to look at. I am in the middle of updating the PHP wrapper to version 3 of the API.

Perignon’s picture

Assigned: Unassigned » Perignon
Perignon’s picture

Status: Active » Postponed (maintainer needs more info)

Can you supply more information from your PHP logs that may show the line number where the problem is occurring? We do not have an explicit rules integration so what you are using is something inherent to Rules. So it is hard for me to reproduce this problem.

Also, if possible, give me explicit steps to reproduce the error. That would greatly help.

Thanks!

supergecko28’s picture

The problem appears to be that sendgrid api expects a "reply-to", and the integration expects "Reply-To". Rules sends the address as reply-to, but somewhere along the line (according to my error log it's line 277 in sendgrid_integration.module), they get mixed up. The emails will still send out with the correct reply-to address, but the user will get the above mentioned error.

I was able to fix the error by generating a new mail class.inc using MailSystem, and modifying the mail function like this (note there is also a fix in here for sending attachments via rules as well, which wasn't working for me originally either):

public function mail(array $message) {
   
      /** fix the missing attachments problem **/

      if(!empty($message['params']['attachments'])){
                    
          $message['attachments'] = $message['params']['attachments'];
          
          foreach($message['attachments'] as $key => $value){
              if(!empty($value['filepath'])){
                  $message['attachments'][$key] = $value['filepath'];
              }
          }
         
      }
       

      /** fix the reply-to problem **/

      if(!empty($message['params']['reply-to'])){
         $message['headers']['Reply-To'] = trim($message['params']['reply-to']);   
      }
      
      return $this->mailClass->mail($message);
}
Perignon’s picture

Like I said above, it would help most if someone could give me explicit steps to reproduce this bug. If I cannot reproduce it is hard to fix it. If you give me a patch, that would help as well.

Perignon’s picture

I understand the Reply-To problem. Drupal core capitalizes the "R" and "T" in the $message array, but Rules does not.

I am about to commit something that should fix that.

As to the attachment problem, start a new issue for that and give me details (like reproducibility :-) )

  • Perignon committed 949085b on 7.x-1.x
    Issue #2848810 by Perignon: Notice: Undefined index: Reply-To in...
Perignon’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Postponed (maintainer needs more info) » Patch (to be ported)

This has to be ported to 8.x branch too

  • Perignon committed eb4bdc4 on 8.x-1.x
    Issue #2848810 by Perignon: Notice: Account for Reply-To being all lower...
Perignon’s picture

Status: Patch (to be ported) » Needs review

This should fix this. The code already accounted for "from" and "From" so I used the same logic so it should function appropriately. Need to get some review/use of this before marking fixed.

Perignon’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

gregori.goossens’s picture

Hi,

for the Drupal 7 version, we have :

if (isset($message['headers']['Reply-To']) || isset($message['headers']['reply-to']) && $message['headers']['reply-to'] = $message['headers']['Reply-To']) {
  $sendgrid_message->setReplyTo($message['headers']['reply-to']);
}

i think code should be :

 if (isset($message['headers']['reply-to']) || ( isset($message['headers']['Reply-To']) && $message['headers']['reply-to'] = $message['headers']['Reply-To'] ) ) {
  $sendgrid_message->setReplyTo($message['headers']['reply-to']);
}

because due to && takes precedence over || and if $message['headers']['Reply-To'] is set (this is the case with test mail form), we don't init $message['headers']['reply-to'].

thks

astolfivincent’s picture

FileSize
956 bytes

This issue is not resolved. The fix in #14 that @gregori.goossens provided is working for me. I'm requesting that this issue be re-opened and that this patch be evaluated:

diff --git a/docroot/sites/all/modules/contrib/sendgrid_integration/inc/sendgrid.mail.inc b/docroot/sites/all/modules/contrib/sendgrid_integration/inc/sendgrid.mail.inc
index 2b2592c5e..fea7fc0e4 100644
--- a/docroot/sites/all/modules/contrib/sendgrid_integration/inc/sendgrid.mail.inc
+++ b/docroot/sites/all/modules/contrib/sendgrid_integration/inc/sendgrid.mail.inc
@@ -281,10 +281,9 @@ class SendGridMailSystem implements MailSystemInterface {
           break;
 
         case 'reply-to':
-          if (isset($message['headers']['Reply-To']) || isset($message['headers']['reply-to']) && $message['headers']['reply-to'] = $message['headers']['Reply-To']) {
+          if (isset($message['headers']['reply-to']) || ( isset($message['headers']['Reply-To']) && $message['headers']['reply-to'] = $message['headers']['Reply-To'] ) ) {
             $sendgrid_message->setReplyTo($message['headers']['reply-to']);
           }
-
           break;
       }

All credit for the patch goes to @gregori.goossens

astolfivincent’s picture

This issue is not resolved. The fix in #14 that @gregori.goossens provided is working for me. I'm requesting that this issue be re-opened and that this patch be evaluated:

diff --git a/docroot/sites/all/modules/contrib/sendgrid_integration/inc/sendgrid.mail.inc b/docroot/sites/all/modules/contrib/sendgrid_integration/inc/sendgrid.mail.inc
index 2b2592c5e..fea7fc0e4 100644
--- a/docroot/sites/all/modules/contrib/sendgrid_integration/inc/sendgrid.mail.inc
+++ b/docroot/sites/all/modules/contrib/sendgrid_integration/inc/sendgrid.mail.inc
@@ -281,10 +281,9 @@ class SendGridMailSystem implements MailSystemInterface {
           break;
 
         case 'reply-to':
-          if (isset($message['headers']['Reply-To']) || isset($message['headers']['reply-to']) && $message['headers']['reply-to'] = $message['headers']['Reply-To']) {
+          if (isset($message['headers']['reply-to']) || ( isset($message['headers']['Reply-To']) && $message['headers']['reply-to'] = $message['headers']['Reply-To'] ) ) {
             $sendgrid_message->setReplyTo($message['headers']['reply-to']);
           }
-
           break;
       }
webadpro’s picture

#8 didnt fix it for me, but #14 sure did.

Thanks @gregori.goossens.

webadpro’s picture

FileSize
699 bytes

Here's a patch

Perignon’s picture

I pushed the changes to dev but they are not showing up here for some reason.