简体   繁体   English

drupal Webform HTML电子邮件挂钩

[英]drupal Webform HTML Email hooks

I'm trying to send a thank you email to the user submitting the form in HTML. 我正在尝试向用户发送一封感谢邮件,以HTML格式提交表单。 I found out by using a hook in my template.php file like this works to set the header correctly: 我通过在我的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;
} 

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. 站点管理员收到的带有表单结果的电子邮件也是html,但并未将换行符转换为该电子邮件中的中断。 I can't figure out how to use a hook for this, so I had to edit the webform.module file and do this: 我不知道如何为此使用钩子,因此我必须编辑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 done with a hook in template.php? 可以用template.php中的钩子来完成吗?

您可以使用hook_mail_alter编辑与创建邮件hook_mail ,这正是Web窗体使用。

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

Old topic but still usefull I guess. 老话题,但我想仍然有用。 On the webform module's edit page there is a option/fieldset with additional processing: 在webform模块的编辑页面上,有一个选项/字段集,其进行了其他处理:

<?php
$to = $form_values['submitted_tree']['uw_gegevens']['e_mail'];
$from = "no-reply@example.com";
$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 Guus van de Wal

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

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