Adding url() breaks hook_mail implementation

此生再无相见时 提交于 2020-01-03 19:02:13

问题


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

回答1:


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.

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



来源:https://stackoverflow.com/questions/5877373/adding-url-breaks-hook-mail-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!