Drupal:从联系表单编辑电子邮件模板

发布于 2024-09-12 10:26:33 字数 541 浏览 0 评论 0原文

当我在 Drupal 6.x 中的站点范围联系表单中提交消息时,我在每条消息的顶部都会收到以下消息:

[姓名] 使用 [www.mysite.com/contact] 上的联系表单发送了一条消息,

我会想删除此消息。环顾四周,我发现它来自 contact.module 这里:

$message['body'][] = t("!name sent a message using the contact form at !form.", array('!name' => $params['name'], '!form' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language))), $language->language);

我做了一些研究,似乎我需要创建一个带有 hook_mail_alter() 函数的自定义模块来编辑 contact.module。当谈到这一点时,我有点迷失了。有人可以指导我完成完成任务的步骤吗?

非常感谢。

When submitting a message in my site-wide contact form in Drupal 6.x I get the following message along the top of every message:

[Name] sent a message using the contact form at [www.mysite.com/contact]

I would like to remove this message. Looking around, I've found it comes from the contact.module here:

$message['body'][] = t("!name sent a message using the contact form at !form.", array('!name' => $params['name'], '!form' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language))), $language->language);

I've done a bit of research and it seems that I need to create a custom module with a hook_mail_alter() function to edit the contact.module. When it comes to this I get a bit lost. Could anyone kindly take me through the steps to accomplish the task?

Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老街孤人 2024-09-19 10:26:33

我最近做了类似的事情。这是一个模板,您可以使用它来获取您需要的内容。大部分来自联系人模块。下面的代码来自 Drupal 7,但在 Drupal 6 中应该可以正常工作。

/**
 * Implementation of hook_mail_alter().
 */
function modulename_mail_alter(&$message) {
  if ($message['id'] == 'contact_page_mail') {
    $language = $message['language'];
    $params = $message['params'];
    $variables = array(
      '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)),
      '!sender-name' => format_username($params['sender']),
      '!sender-url' => $params['sender']->uid ? url('user/' . $params['sender']->uid, array('absolute' => TRUE, 'language' => $language)) : $params['sender']->mail,
    );
    $message['body'] = array();
    $message['body'][] = t("Your custom message with variables", $variables, array('langcode' => $language->language));
    $message['body'][] = $params['message']; // Append the user's message/
  }
}

I did something like that recently. Here is a template you can use to get what you need. Most is from the contact module. The code below is from Drupal 7 but should work as is in Drupal 6.

/**
 * Implementation of hook_mail_alter().
 */
function modulename_mail_alter(&$message) {
  if ($message['id'] == 'contact_page_mail') {
    $language = $message['language'];
    $params = $message['params'];
    $variables = array(
      '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)),
      '!sender-name' => format_username($params['sender']),
      '!sender-url' => $params['sender']->uid ? url('user/' . $params['sender']->uid, array('absolute' => TRUE, 'language' => $language)) : $params['sender']->mail,
    );
    $message['body'] = array();
    $message['body'][] = t("Your custom message with variables", $variables, array('langcode' => $language->language));
    $message['body'][] = $params['message']; // Append the user's message/
  }
}
枕头说它不想醒 2024-09-19 10:26:33
function theme_mail_alter(&$message) {
  // only alter contact forms
  if (!empty($message['id']) && $message['id'] == 'contact_page_mail') {

    $contact_message = $message['params']['contact_message'];

    $message['body'] = [];

    $fields = $contact_message->getFields();
   
    $new_body .= 'Message:' . PHP_EOL . $contact_message->get('message')->value . PHP_EOL . PHP_EOL;

    foreach ($fields as $field_name => $field) {
        if (get_class($field->getFieldDefinition()) == 'Drupal\field\Entity\FieldConfig') {

            $new_body .= $field->getFieldDefinition()->label() . ':' . PHP_EOL;

            if (isset($contact_message->get($field_name)->entity->uri->value)) {
              $uri = $contact_message->get($field_name)->entity->uri->value;
              $url = file_create_url($uri);
              $new_body .=  $url . PHP_EOL . PHP_EOL;

            } else {
              $new_body .= $contact_message->get($field_name)->value . PHP_EOL . PHP_EOL;
            }

        }
    }

    $message['body'][] = $new_body;

  }
}
function theme_mail_alter(&$message) {
  // only alter contact forms
  if (!empty($message['id']) && $message['id'] == 'contact_page_mail') {

    $contact_message = $message['params']['contact_message'];

    $message['body'] = [];

    $fields = $contact_message->getFields();
   
    $new_body .= 'Message:' . PHP_EOL . $contact_message->get('message')->value . PHP_EOL . PHP_EOL;

    foreach ($fields as $field_name => $field) {
        if (get_class($field->getFieldDefinition()) == 'Drupal\field\Entity\FieldConfig') {

            $new_body .= $field->getFieldDefinition()->label() . ':' . PHP_EOL;

            if (isset($contact_message->get($field_name)->entity->uri->value)) {
              $uri = $contact_message->get($field_name)->entity->uri->value;
              $url = file_create_url($uri);
              $new_body .=  $url . PHP_EOL . PHP_EOL;

            } else {
              $new_body .= $contact_message->get($field_name)->value . PHP_EOL . PHP_EOL;
            }

        }
    }

    $message['body'][] = $new_body;

  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文