添加 url() 会破坏 hook_mail 的实现
我正在 Drupal-7 中编写一个模块,该模块动态地向访客发送一次性登录链接。一切都正常,直到我将链接添加到 $message 数组,当它阻塞时。如果我执行 dpm($message)
,链接将出现在 $message['body']
数组中,正如我所期望的那样。如果我用 url() 函数注释掉该行,一切都会按预期进行。为什么 php/Drupal 会因为这个愚蠢的小链接而窒息?
/*
* 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 - 我有代码在单独的函数调用中生成链接,并将其移至钩子实现以简洁起见。然而,这对行为没有影响。
以及生成电子邮件的代码:
function rsvp_mail_send($account) {
$module = 'rsvp';
$from = "[email protected]";
$key = "send invite";
$params['account'] = $account;
$to = $account->mail;
$language = language_default();
$send = TRUE;
$result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
}
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 protected]";
$key = "send invite";
$params['account'] = $account;
$to = $account->mail;
$language = language_default();
$send = TRUE;
$result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要向 url() 函数添加一个额外的参数,称为 options,它是一个数组,在该数组中使用键“absolute”并将其设置为 TRUE 以指示您作为第一个参数传递的 URI 是绝对网址。
请参阅文档页面以获取更多信息:
http://api.drupal.org/api/ drupal/includes--common.inc/function/url/7
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