我无法在drupal-7中发送邮件

时间:2015-10-01 09:56:29

标签: drupal-7

我开始学习drupal,我执行函数发送邮件但失败了。请帮帮我:

 $params = array(
'subject' => 'hello',
'body' => 'test',);
$from='nguyen.xuan.luan@vinicorp.com.vn'; 
$to = 'nguyen.xuan.luan@vinicorp.com.vn';
$mail = drupal_mail('exampe', 'notice', $to, language_default(), $params,  $from, TRUE);

错误消息:无法发送电子邮件。如果问题仍然存在,请与网站管理员联系。

我认为必须有邮件密码的信息,但我不知道如何。请帮帮我?

1 个答案:

答案 0 :(得分:0)

您需要在.module文件中创建一个钩子即hook_mail,并在那里设置消息主题和正文。下面是代码的工作hook_mail()实现 -

function exampe_mail($key, &$message, $params) {
    switch($key) {
        //switching on $key lets you create variations of the email based on the $key parameter
        case 'notice':
            $message['subject'] = t('Subject');
            //the email body is here, inside the $message array
            $message['body'][] = 'This is the body of the email';
         break;
     }
}
相关问题