如何应用电子邮件正文的模板 (tpl) 文件
我的自定义模块中有此邮件功能
function mymodule_mail($key, &$message, $params) {
switch ($key) {
case 'notification':
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
$message['subject'] = $params['subject'];
$message['body'] = t('<table style="border:2px solid black;"><tr><td>MESSAGE BODY </td><td><b>'.$params['msg'].'</b></td></tr></table>');
break;
}
}
在这里您可以清楚地看到对于消息正文我使用了一些 html 标签。
下面的代码调用邮件功能,该功能是在我的块中编写的。
$params = array(
'subject' => 'email subject',
'msg' => 'message body',
);
drupal_mail('mymodule', 'notification', 'email address', language_default(), $params);
我想知道,是否有任何简单的方法可以为我的消息正文应用模板(.tpl.php)文件,以便我可以将所有 css 样式放入该 tpl 文件中。
任何建议将不胜感激。
I've this mail function in my custom module
function mymodule_mail($key, &$message, $params) {
switch ($key) {
case 'notification':
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
$message['subject'] = $params['subject'];
$message['body'] = t('<table style="border:2px solid black;"><tr><td>MESSAGE BODY </td><td><b>'.$params['msg'].'</b></td></tr></table>');
break;
}
}
Here you can clearly see that for message body i'm using some html tags.
Below code invoke the mail function, which is written in my block.
$params = array(
'subject' => 'email subject',
'msg' => 'message body',
);
drupal_mail('mymodule', 'notification', 'email address', language_default(), $params);
I want to know, is there any easy way to apply a template (.tpl.php) file for my message body so that i can put my all css styling within that tpl file.
Any suggestion would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML 邮件模块 就是这样做的:-)
The HTML Mail module does just that :-)
您需要为其设置一个主题调用
现在您已经有了它,您可以更改分配正文的方式
关键
message
需要与您在中提供的参数相匹配mymodule_theme()
,它确实做到了。现在,您只需在模块的
templates/
文件夹中创建 your-template-file.tpl.php (您必须这样做),并且可以使用变量$message
在你的模板中做任何你想做的事情。变量名称与您的主题参数名称相匹配。正确设置模块后,请确保刷新缓存。我无法告诉你我第一次开始使用 Drupal 花了多长时间才意识到,以及我浪费了多少时间试图修复不存在的错误。
You'll need to set up a theme call for it
Now that you have that, you can change the way you're assigning the body
The key
message
needs to match the argument you supplied inmymodule_theme()
, which it does.Now you can just create your-template-file.tpl.php in the module's
templates/
folder (you'll have to make that) and you can use the variable$message
in your template to do whatever you'd like. The variable name matches your theme argument name.After your module is set up properly, make sure to flush the cache. I can't tell you how long it took me to realize that the first time I started working with Drupal, and how much time I wasted trying to fix non-existent bugs.