添加 url() 会破坏 hook_mail 实现

2021-12-29 00:00:00 php drupal drupal-7

我正在用 Drupal-7 编写一个模块,该模块动态地向访客发送一次性登录链接.一切正常,直到我将链接添加到 $message 数组,当它窒息时.如果我执行 dpm($message) 链接会出现在 $message['body'] 数组中,正如我所期望的.如果我用 url() 函数注释掉该行,则一切正常.为什么 php/Drupal 在这个愚蠢的小链接上卡住了?

I'm writing a module in Drupal-7 that dynamically sends a one-time login link to guests. Everything fires fine until I add the link to the $message array, when it chokes. If I do a dpm($message) the link appears in the $message['body'] array, as I would expect. If I comment out the line with the url() function, everything works as it should. Why is php/Drupal choking on this silly little link?

/*
 * Implement hook_mail().
 */

function rsvp_mail($key, &$message, $params) {
    switch($key) {
      case "send invite" :
        $timestamp = REQUEST_TIME;
        $account = $params['account'];
        $message['subject'] = "And invitation for $account->name";
        $message['body'][] = 'Some body text.';
        $message['body'][] = 'Some more text!';
        //here's the line that's breaking my brain:
        $message['body'][] = url( 'http://wedding.juicywatermelon.com/rsvp/' . $account->uid . "/" . $timestamp . "/" . md5($account->pass . $timestamp) . "/" . 'user/' . $account->uid . '/edit/Wedding');             
        break;
    }
  }

ps - 为简洁起见,我有代码在单独的函数调用中生成链接并将其移至钩子实现.然而,这对行为没有影响.

ps - I had the code to generate the link in a seperate function call and moved it to the hook implementation for brevity. This, however had no effect on the behaviour.

以及生成电子邮件的代码:

and the code that generates the email:

function rsvp_mail_send($account) {
  $module = 'rsvp';
  $from = "email@gmail.com";
  $key = "send invite";
  $params['account'] = $account;
  $to = $account->mail;
  $language = language_default();
  $send = TRUE;
  $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
}

推荐答案

你需要在 url() 函数中添加一个额外的参数,称为 options,它是一个数组,在这个数组中使用键 'absolute' 并设置将其设置为 TRUE 表示您作为第一个参数传递的 URI 是绝对 URL.

You need to add an extra argument to the url() function which is called options, it's an array and in this array use the key 'absolute' and set it to TRUE to indicate that the URI that you pass as a first argument is an absolute URL.

查看文档页面了解更多信息:http://api.drupal.org/api/drupal/includes--common.inc/function/url/7

See the documentation page for more information: http://api.drupal.org/api/drupal/includes--common.inc/function/url/7

相关文章