I'm trying to use actions as part of a workflow that would automatically send out an email with html formatting out whenever a node of a certain content type is published using workflow and actions modules. Although my send module has no problem doing this when using the "Send to a Friend" sub-module, when I try reproduce the same functionality through the actions module I can only generate plain text email.s

I looked at the action_send_email function in the actions.inc file and I discovered that the problem is that all the html is bring stripped out of the node body before it is sent at line 327:

'%body' => strip_tags($node->body)

First, could this strip_tags function be removed or is it necessary for some reason?

Second, if the strip_tags function is removed and then the body, now including html, was sent to the drupal_mail function, would this work? I had assumed the actions module was taking advantage of the mime mail module I had installed, but looking at the drupal_mail function in the api, I'm no longer as confident. Do I need to create a whole new action to send the info to a function in the the Send or Mime Mail module?

Comments

davecormier’s picture

funny. i have the same issue.

mennonot’s picture

It's been a while since I posted this issue, but I believe what I did to solve it was add this function to the mimemail.module from the mime mail module

/**
 * Implementation of hook_actions. This creates an action that is selectable via the actions module. 
 * Based directly on function action_send_email from actions.inc in actions module.
 *
 */
function action_send_mime_mail($op, $edit = array(), $node) {
  switch($op) {
    case 'metadata':
      return array(
        'description' => t('Send Email using Mime Mail'),
        'type' => t('Email'),
        'batchable' => false,
        'configurable' => true,
      );

    case 'do':
      // note this is the user who owns the node, not global $user
      $user = user_load(array('uid' => $node->uid));
      $site_name = variable_get('site_name', 'Drupal');
      $from = variable_get('site_mail', ini_get('sendmail_from'));
      $subject = $edit['subject'];
      $message = $edit['message'];
      if ($edit['recipient'] == t('%author')) {
        $recipient = $user->mail;
      } else {
        $recipient = $edit['recipient'];
      }
      if (isset($node) && is_object($node)) {
        $variables = array(
          '%site_name' => $site_name,
          '%username' => $user->name,
          '%uid' => $node->uid,
          '%node_url' => url('node/' . $node->nid, NULL, NULL, TRUE),
          '%node_type' => $node->type,
          '%title' => $node->title,
          '%teaser' => $node->teaser, // removed strip tags from original code
          '%body' => $node->body // removed strip tags from original code
           );

        $subject = strtr($subject, $variables);
        $subject = str_replace(array("\r", "\n"), '', $subject);
        $message = strtr($message, $variables);
      }
      if (mimemail($from, $recipient, $subject, $message)) {
        watchdog('action', t('Sent email to %recipient using mime mail', array('%recipient' => $recipient)));
      }
      else {
        watchdog('error', t('Unable to send email using mime email to %recipient', array('%recipient' => $recipient)));
      }
      break;

    // return an HTML config form for the action
    case 'form':
      // default values for form
      if (!isset($edit['recipient'])) $edit['recipient'] = '';
      if (!isset($edit['subject'])) $edit['subject'] = '';
      if (!isset($edit['message'])) $edit['message'] = '';
      $form = array();

      // add form components
      $form['recipient'] = array(
        '#type' => 'textfield',
        '#title' => t('Recipient'),
        '#default_value' => $edit['recipient'],
        '#size' => '20',
        '#maxlength' => '254',
        '#description' => t('The email address to which the message should be sent OR enter %author if you would like to send an e-mail to the original author of the post.', array('%author' => theme('placeholder', t('%author')))),
      );
      $form['subject'] = array(
        '#type' => 'textfield',
        '#title' => t('Subject'),
        '#default_value' => $edit['subject'],
        '#size' => '20',
        '#maxlength' => '254',
        '#description' => t('The subject of the message.'),
      );
      $form['message'] = array(
        '#type' => 'textarea',
        '#title' => t('Message'),
        '#default_value' => $edit['message'],
        '#cols' => '80',
        '#rows' => '20',
        '#description' => t('The message that should be sent.  You may include the following variables: %site_name, %username, %node_url, %node_type, %title, %teaser, %body'),
      );
      return $form;

     // validate the HTML form
    case 'validate':
      $errors = array();

      if (!valid_email_address($edit['recipient']) && $edit['recipient'] != t('%author')) {
        $errors['recipient'] = t('Please enter a valid email address or %author.', array('%author' => theme('placeholder', t('%author'))));
      }
      foreach ($errors as $name => $message) {
        form_set_error($name, $message);
      }

      return count($errors) == 0;

    // process the HTML form to store configuration
    case 'submit':
      $params = array(
        'recipient' => $edit['recipient'],
        'subject'   => $edit['subject'],
        'message'   => $edit['message']);
      return $params;
  }
}

You can then select this new "Send Email using Mime Mail" action as part of a workflow.

mennonot’s picture

This "Send Email using Mime Mail" action was working great for me in 5.x, but I recently upgraded the site to 6.x. I've got the mime mail module installed, but this action is gone. I tried using the plain "Send Email" action, but it strips out html tags in the %body when it gets emailed out.

I realize this might be an issue for the mime mail module, but I thought I'd try posting it in this thread first since this is one of the only ones that mentions the existence of a "Send Email using Mime Mail" action.

pomliane’s picture

Status: Active » Closed (won't fix)

This version of Actions is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.

This issue has been automagically closed by a script.