Drupal 如何发送邮件
Drupal how to send a mail
我正在尝试向用户发送自定义邮件,在我创建这两种方法的模块中:
/**
* Implements hook_theme().
*/
function ga_planning_theme() {
return array(
'ga_planning_mail_status_change' => array(
'template' => 'templates/ga_planning_mail_status_change',
'variables' => array(),
)
);
}
/**
* Implements hook_mail().
*/
function ga_planning_mail($key, &$message, $params) {
switch ($key) {
case 'status_change_mail':
$message['subject'] = t('Changement de statut');
$message['body'][] = theme('ga_planning_theme', $params);
break;
}
}
然后我尝试用 drupal_mail 发送邮件:
drupal_mail('ga_planning', 'ga_planning_mail_status_change', "myadress@mail.com", NULL, $params, variable_get('site_mail'), TRUE);
但邮件没有发送,它使用默认模板和主题向网站管理员邮件发送邮件:
DEBUG - FROM MyWebsite.com
我做错了什么?
首先,请确保您可以发送电子邮件,其次:
您需要定义 $params 数组。例如:
$params['test'] = 'ok';
另外,尝试声明 headers:
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
$message['subject'] = t('Changement de statut');
$message['body'][] = theme('ga_planning_theme', $params);
我正在尝试向用户发送自定义邮件,在我创建这两种方法的模块中:
/**
* Implements hook_theme().
*/
function ga_planning_theme() {
return array(
'ga_planning_mail_status_change' => array(
'template' => 'templates/ga_planning_mail_status_change',
'variables' => array(),
)
);
}
/**
* Implements hook_mail().
*/
function ga_planning_mail($key, &$message, $params) {
switch ($key) {
case 'status_change_mail':
$message['subject'] = t('Changement de statut');
$message['body'][] = theme('ga_planning_theme', $params);
break;
}
}
然后我尝试用 drupal_mail 发送邮件:
drupal_mail('ga_planning', 'ga_planning_mail_status_change', "myadress@mail.com", NULL, $params, variable_get('site_mail'), TRUE);
但邮件没有发送,它使用默认模板和主题向网站管理员邮件发送邮件:
DEBUG - FROM MyWebsite.com
我做错了什么?
首先,请确保您可以发送电子邮件,其次: 您需要定义 $params 数组。例如:
$params['test'] = 'ok';
另外,尝试声明 headers:
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
$message['subject'] = t('Changement de statut');
$message['body'][] = theme('ga_planning_theme', $params);