问题
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