简体   繁体   中英

drupal Webform HTML Email hooks

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?

您可以使用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:

<?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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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