我使用联系人模块向我的电子邮箱发送电子邮件,如何自定义电子邮件正文?默认值为:
the user name (http://example.com/user/3) use
http://example.com/contact ...
the message body
我已经使用hook_form_alter
向联系我们添加了一些字段form.eg:phone,address,company name.email dress,如何在电子邮件正文中显示它们。谢谢。
答案 0 :(得分:3)
考虑使用webform module。您不需要实现任何挂钩来添加字段或配置通过电子邮件发送的字段。
Drupal的联系模块
更容易答案 1 :(得分:2)
穆罕默德建议我们应该使用Webform module添加字段的良好解决方案。这样你就不需要编写任何代码了。
根据您的具体需要,您可以使用hook_mail_alter来帮助您更改电子邮件,还可以在电子邮件正文中添加额外的字段。
答案 2 :(得分:2)
正如您在contact.module中所看到的,有一些预定义的硬编码变量。如果您将自己的字段添加到表单中,则它们不适用于邮件。
为了使它们在那里可用,您需要编写,注册和编写自己的邮件处理程序;
function email_example_mail($key, &$message, $params) {
global $user;
$options = array(
'langcode' => $message['language']->language,
);
switch ($key) {
case 'contact_message':
$message['subject'] = t('E-mail sent from @site-name', array('@site-name' => variable_get('site_name', 'Drupal')), $options);
$message['body'][] = t('@name sent you the following message:', array('@name' => $user->name), $options);
$message['body'][] = check_plain($params['message']);
break;
}
}
然后发送邮件的方法:
function email_example_mail_send($form_values) {
$module = 'email_example';
$key = 'contact_message';
$to = $form_values['email'];
$from = variable_get('site_mail', 'admin@example.com');
$params = $form_values;
$language = language_default();
$send = TRUE;
$result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
if ($result['result'] == TRUE) {
drupal_set_message(t('Your message has been sent.'));
}
else {
drupal_set_message(t('There was a problem sending your message and it was not sent.'), 'error');
}
}
然后将从自定义提交处理程序中调用此方法:
function email_example_contact_form_submit($form, &$form_state) {
email_example_mail_send($form_state);
}
您在hook_form_alter
注册的内容(我不知道核心联系表单的确切form_id,请放置contact
的位置):
function email_example_contact_form_alter($form, &$form_state) {
$form['#submit']['my_very_own_submit'] = array();
}
答案 3 :(得分:2)
Entityforms模块使用标准的Drupal字段,这意味着您可以使用任何标准的Drupal字段。对于那些使用过Webforms的人来说,这个模块将Webform的功能带入"标准" Drupal领域/实体世界。
虽然Webform是一个具有巨大追随者的优秀模块,但它不会与标准的Drupal字段或实体感知模块集成。因此,对于Drupal 7站点,建议使用Entityforms模块!
与Webform一样,它可以很好地与Rules模块集成,用于表单提交通知,并允许复杂的通知逻辑。