简体   繁体   English

使用Drupal 7中的Webform模块以HTML格式将电子邮件发送给表单提交者和管理员

[英]Send email to form submitters and admin in HTML format using webform module in drupal 7

I am using the web-form module in drupal7 and I have to configure email using web form for administrator as well as the users who submit the form. 我正在drupal7中使用Web表单模块,并且必须使用Web表单为管理员以及提交表单的用户配置电子邮件。 I can easily configure email for administrator using email setting but can not configure for the user who submit the form because initially I do not have email address of the users who submit the form. 我可以使用电子邮件设置轻松为管理员配置电子邮件,但不能为提交表单的用户进行配置,因为最初我没有提交表单的用户的电子邮件地址。

You can manage it via your module like below, 您可以通过下面的模块进行管理,

Write webform submission hook and send your html formatted mail to the email id 编写Webform提交钩子,并将html格式的邮件发送到电子邮件ID

// webform submission hook
function MODULENAME_webform_submission_insert($node, $submission) {
    global $user,$language;
    $to = $user->mail;
    $params = array(
                    'body' => "<p> Your html content</p>",
                    'subject' => "You mail subject",
                );
    drupal_mail("MODULEANME", "mail-test", $to, $language, $params);
}

then write your own mail hook with html as content type, 然后用html作为内容类型编写您自己的邮件挂钩,

// mail hook
function MODULENAME_mail($key, &$message, $params) {
    switch ($key) {
        case 'mail-test':
            $message['subject'] = t($params['subject']);
            $message['body'][] = $params['body'];
            $message['headers']['Content-Type'] = 'text/html; charset=utf-8';
            break;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM