2013-01-10 97 views
1

我使用联系模块发送电子邮件到我的邮箱,如何定制电子邮件正文?默认为:drupal 7联系我们表格发送电子邮件

the user name (http://example.com/user/3) use 
http://example.com/contact ... 

the message body 

我已经使用hook_form_alter加入一些领域与我们联络form.eg:phone,地址,公司name.email装扮,如何让他们显示在电子邮件正文中。谢谢。

回答

3

考虑使用webform module。您不需要实施任何挂钩来添加字段或配置通过电子邮件发送的字段。

这是一个更容易的是Drupal的联系人模块

2

穆罕默德曾建议,我们应该用Webform module添加字段很好的解决方案。这样你就不需要编写任何代码。

根据您的具体需求,您可以使用hook_mail_alter这将帮助您更改电子邮件消息,并且您可以在电子邮件正文中添加额外的字段。

+0

如果我使用hook_mail_alter谢谢 – stack2013110

2

正如你在contact.module中看到的那样,有几个预定义的硬编码变异函数。如果您将自己的字段添加到表单中,则它们不适用于邮件。

为了使它们在那里可用,您需要编写,注册和编写您自己的邮件处理程序;

实施hook_mail

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', '[email protected]'); 

    $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(); 
} 

from example for developers

+0

您是否需要创建一个模块?我把你的代码放在一个模块文件中,但它仍然不能工作 – stack2013110

+0

当然你必须编程一个模块,那是你问到的,不是? – berkes

2

Entityforms模块使用标准Drupal的领域,这意味着你可以使用任何标准Drupal字段。对于那些使用过Webforms的人来说,该模块将Webform的功能带入了标准的Drupal领域/实体世界。

虽然Webform是一个非常棒的模块,但它并没有集成标准的Drupal字段或实体感知模块。所以对于Drupal 7网站,建议使用Entityforms模块!

和Webform一样,它与Rules模块很好地集成在一起,用于表单提交通知并允许复杂的通知逻辑。

相关问题