开发者

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']开发者_如何学Python = $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?


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜