0

Does anyone have a solution to adding a CC field to the /node/[nid]/webform/emails/xxx interface?

I have a client that wants to use a decently complex conditional email send solution in Drupal 7 webform, where based on various select lists, it will send an email to two places.

  1. "[email protected]"

  2. "[email protected]"

Allowing a real person to be notified and respond via REPLY-ALL to the email, and having the ticket system be updated with the communication in real time.

The ticket system can't handle getting a reply-to with both addresses in the single "TO:" line.

to: [email protected],[email protected] breaks the system.

Has anyone solved this? built a module? Have guidance on how to solve?

Thank you!

Add a CC field to webform emaill addresses

2 Answers 2

0

I have done some similar thing to send the email to another email-address. You can use the following solution for changing the content of the email or to add an attachment or things like this...

/**
 * Implements hook_mail_alter().
 */
function MYMODULE_mail_alter(&$message) {
  // Check message id
  if ($message['id'] == '...') {
    $email_key = 'new_email_key_if_you_want';

    // Block email which is sending right now.
    $message['send'] = FALSE;

    // send original email
    drupal_mail('MYMODULE', $email_key, $message['to'], language_default(), $message['params'], $message['from']);

    // send copy of the email.
    drupal_mail('MYMODULE', $email_key, '[email protected]', language_default(), $message['params'], $message['from']);
  }
}

You can add this in an own module, in the MYMODULE.module.

2
  • Thank you. Does if($message['id']...) allow me to define different CC addresses based on the which webform email condition is triggered?
    – alphex
    Commented Jan 12, 2018 at 16:16
  • Hi @alphex Mh i'm not sure. Probably yes: each type of email in drupal gets a individual key. Either it is an email-key based on the webforms (each type of webform gets an own key) or, (and this would be bad for you) the key is based just on the module webform. You have to try.
    – btemperli
    Commented Jan 13, 2018 at 6:44
0

I have done this by adding the below code to my custom module. Use hook_mail_alter().

function mymodule_mail_alter(&$message) { 
   if ($message['id'] == 'webform_submission') {
     if ($message['params']['node']->nid == 'webform_node_id') {
    $message['headers']['CC'] = '[email protected]'; 
     }
   }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.