0

So I have a node that is using the Print Module (www.drupal.org/project/print) and it's associated send by email functionality.

The issue is that if I include multiple emails on the send by email page, it sends them so that the email addressees cannot see the other people it was emailed to.

For instance, if my send to looks like: example1@example.com, example2@example.com

Both example1 and example2 will receive the email, but with only their name in the To: line. Is there a way to get the rest of them to show up there as well, or in the CC: line?

Thanks.

Here's the portion of the code I was able to find where it splits it into multiple emails:

  $addresses = explode(', ', $form_state['values']['txt_to_addrs']);
  foreach ($addresses as $to) {
    if ($use_job_queue) {
      // Use job queue to send mails during cron runs
      $queue->createItem(array('module' => 'print_mail', 'key' => $print_mail_send_option_default, 'to' => $to, 'language' => language_default(), 'params' => $params, 'from' => $from));
    }
    else {
      // Send mail immediately using Drupal's mail handler
      $ret = drupal_mail('print_mail', $print_mail_send_option_default, $to, language_default(), $params, $from);
    }
    if ($use_job_queue || $ret['result']) {
      flood_register_event('print_mail');
      $ok = TRUE;
    }
  }

Anyone know how I can make that so it just sends one email to all of the addresses?

0

One possible way would be use that a form_alter to make sure that there are no commas in the "to" list (i.e. replace all commas with semi-colons), and then use hook_mail_alter to revert the replacement.

That being said, I do find the use case here funny.. I specifically designed this code to prevent what you want to do in order to protect the privacy of each email recipient.

  • Yeah, I kind of figured as much. The email that is being sent out in this case, and its very specific so I wouldn't expect you to change the module for it, is that one of the members needs to see the email address of the other so they know who to send a followup email to about collecting money. The way it currently is, they just get the email to them, and don't know the other recipient of the email who they need to then get in contact with. – Dan Apr 15 '16 at 13:42
0

You could try the hook_mail_alter() which lets you intercept emails used by drupal_mail(), but that's problematic since, as you mentioned, each email gets sent out individually.

There's a hook_print_mail_alter() invocation before the email is sent, but this is problematic too since $params doesn't have the email recipients.

The route I would take is to alter the email form submission handler with your own custom submission based off the print module's implementation:

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'print_mail_form') {
    $form['#submit'] = array(
      'MYMODULE_print_mail_form_submit'
    );
  }
}

/**
 * Submission Handler.
 */
function MYMODULE_print_mail_form_submit($form, &$form_state) {
  //@TODO: Implement your own email code.

  //print_mail_form_submit($form, $form_state);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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