我是一个非常新的drupal表单但已设法设置drupal_mail
函数,在提交后会使用正确的$subject
邮件和$from
电子邮件地址向所需位置发送电子邮件。但是,它不是发送消息正文。我用google搜索/尝试过很多东西,但似乎没有什么能抓住正确的价值。谁能明白为什么?在此先感谢您的帮助。
function drupalform_menu() {
$items['drupalform/form1'] = array(
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
'page callback' => 'drupal_get_form',
'page arguments'=>array('drupalform_form1'));
return $items;
} ?>
<?php function drupalform_form1() {
$form = array(
'#prefix' => '<div id="contact-form" class="row section"><div
class="container">',
'#suffix' => '</div></div>',
); ?>
<?php $form['name']=array(
'#prefix' => '<div class="col l5 s12">',
'#type'=>'textfield',
'#title'=>t('FIRST & LAST NAME'),
); ?>
<?php $form['email']=array(
'#suffix' => '</div>',
'#type'=>'textfield',
'#title'=>t('EMAIL'),
); ?>
<?php $form['message']=array(
'#prefix' => '<div id="form-message" class="col l5 push-l1 s12 ">',
'#type'=>'textarea',
'#title'=>t('MESSAGE'),
); ?>
<?php $form['submit']=array(
'#suffix' => '</div>',
'#type'=>'submit',
'#value'=>t('SEND MESSAGE')
);
return $form; ?>
<?php } ?>
<?php
function drupalform_form1_submit($form, $form_state) {
$to = "test@test.com";
$from = "sender@sender.com";
$subject = "New message from the Louisville Digital Inclusion Site";
$body = $form_state['values']['message'];
$params = array(
'subject' => $subject,
'body' => $body,
);
drupal_mail('test', 'information', $to, language_default(), $params, $from);
drupal_set_message("Form has been submitted");
}
function test_mail($key, &$message, $params) {
switch ($key) {
case 'information':
$message['subject'] = $params['subject'];
$message['body'] = $params['body'];
break;
}
}
?>
答案 0 :(得分:0)
弄清楚了!我必须将test_mail
函数更改为如下所示:
function test_mail($key, &$message, $params) {
switch ($key) {
case 'information':
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
break;
}
}
我需要在$message['body'][] = $params['body']
之后添加空括号。