drupal Webform HTML 电子邮件挂钩

发布于 2024-09-24 02:04:27 字数 914 浏览 0 评论 0原文

我正在尝试向以 HTML 格式提交表单的用户发送一封感谢电子邮件。 我发现通过在 template.php 文件中使用钩子可以正确设置标题:

function mythemename_webform_mail_headers($form_values, $node, $sid) {
  $headers = array(
    'Content-Type'  => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
    'X-Mailer'      => 'Drupal Webform (PHP/'. phpversion() .')',
  );

  return $headers;
} 

这对于“谢谢”电子邮件非常有效。 网站管理员收到的带有表单结果的电子邮件也是 html,但它不会将换行符转换为该电子邮件中的中断符。我不知道如何为此使用挂钩,因此我必须编辑 webform.module 文件并执行以下操作:

function webform_mail($key, &$message, $params) {
  $message['headers'] = array_merge($message['headers'], $params['headers']);
  $message['subject'] = $params['subject'];
  //$message['body'][] = drupal_wrap_mail($params['message']); // replaced this with line below
  $message['body'][] = nl2br(drupal_wrap_mail($params['message']));
}

Can this be did with a hook in template.php?

I'm trying to send a thank you email to the user submitting the form in HTML.
I found out by using a hook in my template.php file like this works to set the header correctly:

function mythemename_webform_mail_headers($form_values, $node, $sid) {
  $headers = array(
    'Content-Type'  => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
    'X-Mailer'      => 'Drupal Webform (PHP/'. phpversion() .')',
  );

  return $headers;
} 

This works freat for the "Thank You" email.
The email that the site admin gets with the form results is also html, but it's not converting newlines to breaks in this email. I can't figure out how to use a hook for this, so I had to edit the webform.module file and do this:

function webform_mail($key, &$message, $params) {
  $message['headers'] = array_merge($message['headers'], $params['headers']);
  $message['subject'] = $params['subject'];
  //$message['body'][] = drupal_wrap_mail($params['message']); // replaced this with line below
  $message['body'][] = nl2br(drupal_wrap_mail($params['message']));
}

Can this be done with a hook in template.php?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鲸落 2024-10-01 02:04:27

您可以使用 hook_mail_alter 编辑使用以下命令创建的邮件hook_mail,这是 Webform 使用的。

You can use hook_mail_alter to edit mails created with hook_mail, which is what webform uses.

吾性傲以野 2024-10-01 02:04:27

您不能在主题中使用 hook_mail_alter(),只能在自定义模块中使用。

You can't use hook_mail_alter() in a theme, only in a custom module.

合久必婚 2024-10-01 02:04:27

老话题但我想仍然有用。在网络表单模块的编辑页面上,有一个带有附加处理的选项/字段集:

<?php
$to = $form_values['submitted_tree']['uw_gegevens']['e_mail'];
$from = "[email protected]";
$achternaam = $form_values['submitted_tree']['uw_gegevens']['uw_naam'];


$message = drupal_mail('webform_extra', 'reply', $to, language_default(), array('body' => $body), $from, TRUE);

function webform_extra_mail($key, &$message, $params) {
  $message['subject'] = "TEXT.";


  $message['body'] = "
TEXT, " . $params['achternaam'] . "
TEXT. 


KIND REGARDS,
TEXT
";


} ?>

希望这对

Guus van de Wal有帮助

Old topic but still usefull I guess. On the webform module's edit page there is a option/fieldset with additional processing:

<?php
$to = $form_values['submitted_tree']['uw_gegevens']['e_mail'];
$from = "[email protected]";
$achternaam = $form_values['submitted_tree']['uw_gegevens']['uw_naam'];


$message = drupal_mail('webform_extra', 'reply', $to, language_default(), array('body' => $body), $from, TRUE);

function webform_extra_mail($key, &$message, $params) {
  $message['subject'] = "TEXT.";


  $message['body'] = "
TEXT, " . $params['achternaam'] . "
TEXT. 


KIND REGARDS,
TEXT
";


} ?>

Hope this helps

Guus van de Wal

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文