添加url()会中断hook_mail的实现 [英] Adding url() breaks hook_mail implementation

查看:98
本文介绍了添加url()会中断hook_mail的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Drupal-7中写一个模块,动态地向客人发送一次性登录链接。所有的东西都可以正常运行,直到我添加到 $ message 数组的链接。如果我执行 dpm($ message),链接将显示在 $ message ['body'] 数组中,如我会期望的如果我注释掉与 url()函数的一行,一切都应该是正常的。为什么php / Drupal窒息在这个愚蠢的小链接?

  / * 
*实现hook_mail()。
* /

函数rsvp_mail($ key,& $ message,$ params){
switch($ key){
casesend invite:
$ timestamp = REQUEST_TIME;
$ account = $ params ['account'];
$ message ['subject'] =和$ account-> name的邀请;
$ message ['body'] [] ='一些正文文本'。
$ message ['body'] [] ='一些更多的文字!';
//这是打破我大脑的线:
$ message ['body'] [] = url('http://wedding.juicywatermelon.com/rsvp/'。$ account-> uid。/。$ timestamp。/。md5($ account-> pass。$ timestamp)。/。'user /'。$ account-> uid。'/ edit / Wedding');
break;
}
}

ps - 我有代码来生成链接一个单独的函数调用,并将其移动到钩子实现简洁。然而,这对行为没有影响。



和生成电子邮件的代码:

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


解决方案

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



有关详细信息,请参阅文档页面:
http://api.drupal.org/api/drupal/includes--common.inc/function/url/7


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

解决方案

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

这篇关于添加url()会中断hook_mail的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆