Drupal 7 - 向用户发送有关内容修改的电子邮件

Drupal 7 - Send an E-mail to user on content modification

我有一个网络表单页面,用户可以在其中提交查询。提交表单时,会向用户和管理员发送一封确认邮件。我已经安装了 Custom Webform Comment 模块,用户和管理员都可以通过该模块评论和更改表单中的状态,现在我想将每个评论和状态更改的邮件发送给管理员和用户。

我试过使用 Webform Rules 模块,但它不起作用。该模块不发送邮件

有没有其他方法或模块可以向用户发送邮件?

网络表单版本7.x-4.15

提前致谢:)

您可以在自定义表单中使用 hook_webform_submission_update 发送电子邮件,或者您可以为此使用操作和触发

  1. 为此你必须添加新的自定义模块,你可以参考这个 link :- https://www.drupal.org/docs/7/creating-custom-modules/getting-started

  2. 在您的 custom.module 文件中添加此代码

参考此代码

 function <moduleName>_webform_submission_update($node, $submission)
        {
                        // you can send mail like this
                        $message = 'New signup email address'; // Body of your email here. 
                        //you can also set any form detail using $node,$submission variable
                        $params = array(
                               'body' => $message,
                               'subject' => 'Website Information Request',
                               'headers'=>'simple',
                         );
                         $to = "Your Email Address";
                        drupal_mail('contactform', 'send_link', $to, language_default(), $params, 'demo@demo.com', TRUE);

         }

我通过在 Custom Webform Comment 模块中插入 hook_mail 代码解决了上述问题。

如果其他人遇到同样的问题,这里是我在 custom_webform_comments.module 文件中插入的代码。

/**
 * Implements hook_mail().
 */
function custom_webform_comments_mail($key, &$message, $params) {
  switch($key) {
    case 'custom_webform_comments_email':
      $message['subject'] = t('Submit Request Form update');
      $message['body'][] = t('You have got a new comment and status update on your submitted form.',array('@site-name' => variable_get('site_name','example.com')));
       $message['body'][] = t(variable_get('custom_webform_comments_email_text',''));
      break;
  }
}

在上面的代码行之后,将以下代码放在函数 custom_webform_comments_commentform_submit() 中的数据库插入查询之后,以便在每次评论更新后发送邮件。

function custom_webform_comments_commentform_submit($form, $form_state) {
  $fv = $form_state['values'];
  $insert1 = db_insert('custom_webform_comments')
    ->fields(array(
      'cid' => NULL,
      'comment' => $fv['addnew']['comment'],
      'subject' => $fv['addnew']['subject'],
      'nid' => $fv['addnew']['nid'],
      'sid' => $fv['addnew']['sid'],
      'commenter_user_id' => $fv['addnew']['commenter_user_id'],
      'comment_parent' =>  '0',
      'ts' => date("Y-m-d H:i:s")
      ))->execute();
    if($insert1)
    {
        global $user; 
        $params = array(
           'body' => $message,
           'subject' => 'Website Information Request',
           'headers'=>'simple',
        );
        $message = drupal_mail('custom_webform_comments', 'custom_webform_comments_email', $user->mail, language_default(), $params, 'test@example.com', TRUE);
        if (!empty($message['result'])) {
            watchdog('mail', 'Mail sent Successfully (from %from to %to) for comment update', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_NOTICE);
            //drupal_set_message("Mail sent!");
        }
        else{
            watchdog('mail', 'Error sending e-mail (from %from to %to).', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_ERROR);
            drupal_set_message(t('Unable to send e-mail. Contact the site administrator if the problem persists.'), 'error');
        }
    }
    return $insert1; 
}

同样要在每次状态更新时收到邮件,请更新以下函数。

function custom_webform_comments_status_dbupdater($data) {
  global $user;
  //Insert values into database
  $insert = db_insert('custom_webform_submission_status')
    ->fields(array(
      'id' => NULL,
      'status' => $data['status'],
      'submit_time' => date("Y-m-d H:i:s"),
      'nid' => $data['nid'],
      'sid' => $data['sid'],
      'user' => serialize($user)
    ))->execute();
    if($insert)
    {
        global $user; 
        $params = array(
           'body' => $message,
           'subject' => 'Website Information Request',
           'headers'=>'simple',
        );
        $message = drupal_mail('custom_webform_comments', 'custom_webform_comments_email', $user->mail, language_default(), $params, 'test@example.com', TRUE);
        if (!empty($message['result'])) {
            watchdog('mail', 'Mail sent Successfully (from %from to %to) for status update', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_NOTICE);
            //drupal_set_message("Mail sent!");
        }
        else{
            watchdog('mail', 'Error sending e-mail (from %from to %to).', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_ERROR);
            drupal_set_message(t('Unable to send e-mail. Contact the site administrator if the problem persists.'), 'error');
        }
    }
  return $insert;
}