Drupal - use l or url function for mailto links

13,458

Solution 1

You need to use the absolute option:

l('Mail me', 'mailto:[email protected]', array('absolute' => TRUE));

will generate

<a href="mailto:[email protected]">Mail Me</a>

Solution 2

A good practice is to use the t() function with strings. Code should be then:

l(t('Mail me'), 'mailto:[email protected]', array('absolute' => TRUE));
Share:
13,458
frankish
Author by

frankish

Worked most of my career in Linux/UNIX environments with Perl, Java, Sybase. Worked as a Developer, QA Engineer and UNIX Systems Admininstrator I like to ask the good questions so all can benefit from the answers. Hard to beat the fastest guns in the west around here. ;-)

Updated on June 05, 2022

Comments

  • frankish
    frankish almost 2 years

    Does anyone know how to use the l() or url() function to create mailto links?

    I am running drupal 6.

  • Weboide
    Weboide about 12 years
    You may want to add quotes around 'absolute'. Just for people out there learning PHP...
  • M-Chen-3
    M-Chen-3 about 3 years
    Please explain what your code does and how it does it.