Does Drupal's theme('table') works in email body? 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' =&gt; t('Title'), 'field' =&gt; 'n.title'),
            array('data' =&gt; t('Author'), 'field' =&gt; 'u.name'),
    );
    $query = db_select('node', 'n');
    $query-&gt;leftjoin('users', 'u', 'u.uid = n.uid');
    $query-&gt;fields('n',array('title', 'created', 'nid', 'type'))
    -&gt;fields('u',array('name', 'uid'))
    -&gt;fields('b',array('body_value'))
    -&gt;fields('c',array('subject'));
    $query-&gt;condition(db_or()-&gt;condition('n.type', 'post', '=')-&gt;condition('n.type', 'forum', '='));
    $query-&gt;condition('n.uid', $user-&gt;uid, '=');
    $result = $query-&gt;execute();
    $rows = array();
    foreach ($result as $row) {
        if($row-&gt;subject) {
            $titlerow = l($row-&gt;subject, 'node/'. $row-&gt;nid).'&lt;/br&gt;'. $row-
        }
        $rows[] = array( $titlerow,
                t('Reply Posted by: ').l($row-&gt;name, 'user/'. $row-&gt;uid)
        );
    }
    $params = theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows, array('class' =&gt; 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.'));
    }
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-&gt;subject) {
  $titlerow = l($row-&gt;subject, "node/{$row-&gt;nid}", array('absolute' =&gt; TRUE)) . '&lt;/br&gt;' // Your code here is not complete.
}
$rows[] = array(
  $titlerow,
  t('Reply posted by !user-link', array('!user-link' =&gt; l($row-&gt;name, "user/{$row-&gt;uid}", array('absolute' =&gt; 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' =&gt; TRUE));


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

&lt;a href="/dr72/node/1"&gt;Test page&lt;/a&gt;
&lt;a href="http://tero.local/dr72/node/1"&gt;Test page&lt;/a&gt;


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