I want to send the list of some of the node information in email to users.

I have created table of information using theme('table') function. Now I want to send this table to email to user.

Is it possible to send theme('table') using Email ?

Will it work when user will see the information in Email ?

I am sending table structure in Email, is this possible to achieve it?

I have attached the relevant code to generate table and send mail.

$header = array(
            array('data' => t('Title'), 'field' => 'n.title'),
            array('data' => t('Author'), 'field' => 'u.name'),
    $query = db_select('node', 'n');
    $query->leftjoin('users', 'u', 'u.uid = n.uid');
    $query->fields('n',array('title', 'created', 'nid', 'type'))
    ->fields('u',array('name', 'uid'))
    $query->condition(db_or()->condition('n.type', 'post', '=')->condition('n.type', 'forum', '='));
    $query->condition('n.uid', $user->uid, '=');
    $result = $query->execute();
    $rows = array();
    foreach ($result as $row) {
        if($row->subject) {
            $titlerow = l($row->subject, 'node/'. $row->nid).'</br>'. $row-
        $rows[] = array( $titlerow,
                t('Reply Posted by: ').l($row->name, 'user/'. $row->uid)
    $params = theme('table', array('header' => $header, 'rows' => $rows, array('class' => array('ajax-sample-table'))));
    $language = language_default();
    $send = TRUE;
    $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
    if ($result['result'] == TRUE) {
        drupal_set_message(t('Your message has been sent.'));

1 Answer 1


You can read drupal_mail() in HTML for how to output HTML in an email sent with drupal_mail().

As you are outputting links, I will add a note about that. By default l() outputs relative links that outside the website are not much useful. You need to force Drupal to output absolute links, for example using the following code.

if ($row->subject) {
  $titlerow = l($row->subject, "node/{$row->nid}", array('absolute' => TRUE)) . '</br>' // Your code here is not complete.
$rows[] = array(
  t('Reply posted by !user-link', array('!user-link' => l($row->name, "user/{$row->uid}", array('absolute' => TRUE)))) 

If you have the Devel module installed, you can see (using the following code) the difference between the output of your code, and mine.

print l('Test page', 'node/1') . "\n";
print l('Test page', 'node/1', array('absolute' => TRUE));

In my test site, what I get is the following.

<a href="/dr72/node/1">Test page</a>
<a href="http://tero.local/dr72/node/1">Test page</a>

As side note, remember that the $options parameter for l() can receive the same values the $options parameter for url() accepts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.