39

Goal: To send an email with a list of URLs generated from nodes.

In my custom module I have managed to get the node id which the user wants and I now want to get the URL of each node to put into my email.

I searched the db and used google but I can't seem to find the right solution.

It seems we need to construct the URL something like this:

<?php
global $base_url;
$link=$base_url."// few more parameters 
Martin Rugadya
  • 584
  • 7
  • 14
Vishal Khialani
  • 2,557
  • 6
  • 38
  • 49

5 Answers5

91

You can use the url() function:

$options = array('absolute' => TRUE);
$nid = 1; // Node ID
$url = url('node/' . $nid, $options);

That will give you the absolute path (i.e. with http://example.com/ in front of it), with the URL aliased path to the node page.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Clive
  • 36,918
  • 8
  • 87
  • 113
15

You can also try drupal_lookup_path('alias',"node/".$node->nid).

Laxman13
  • 5,226
  • 3
  • 23
  • 27
scotself
  • 179
  • 5
7

Also you can get it by

$path=drupal_get_path_alias('node/'.$nid);

absolute path for nid

url('node/' . $node->id(), ["absolute" => TRUE]);
Yuseferi
  • 7,931
  • 11
  • 67
  • 103
4

You can also use the l() function.

  l(t('Link text'), 'node/123', array('options' => array('absolute' => TRUE)));
mattwith
  • 53
  • 4
-5

use

$node_url;

it will give you the current node url

manish
  • 1