drupal Webform HTML 电子邮件挂钩
我正在尝试向以 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
hook_mail_alter
编辑使用以下命令创建的邮件hook_mail
,这是 Webform 使用的。You can use
hook_mail_alter
to edit mails created withhook_mail
, which is what webform uses.您不能在主题中使用 hook_mail_alter(),只能在自定义模块中使用。
You can't use hook_mail_alter() in a theme, only in a custom module.
老话题但我想仍然有用。在网络表单模块的编辑页面上,有一个带有附加处理的选项/字段集:
希望这对
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:
Hope this helps
Guus van de Wal