代码之家  ›  专栏  ›  技术社区  ›  hiral vadhel

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

  •  0
  • hiral vadhel  · 技术社区  · 6 年前

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

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

    是否有其他方式或模块可用于向用户发送邮件?

    Webform版本7。x-4.15

    提前感谢:)

    2 回复  |  直到 6 年前
        1
  •  1
  •   Swati Dave    6 年前

    您可以在自定义表单中使用hook\u webform\u submission\u update发送电子邮件,也可以使用action和triger发送电子邮件

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

    2. 按照您的习惯。模块文件添加此代码

    参考此代码

     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);
    
             }
    
        2
  •  0
  •   hiral vadhel    6 年前

    我通过在我的 Custom Webform Comment 单元

    如果其他人也面临同样的问题,这里是我在custom\u webform\u注释中插入的代码。模块文件。

    /**
     * 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\u webform\u comments\u commentform\u 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;
    }