triggering email from custom module I have a module that uses hook_menu to create several pages that are populated with SQL query results.

I have been trying to configure drupal_mail and hook_mail to send these results via mail when the pages are visited, but so far I haven't succeeded.

I used the info I found here and indeed, the module works: whenever I run cron the sample mail is sent, but I haven't found the way to customize it in my module so when I load my custom pages the results are sent via mail.

Also, if my data is the result of:

function mystats_all() {

$header = array('Nombre', 'Status', 'Rol 5 = Alumno', 'Email' );

$query = "
SELECT name, status, rid, mail
FROM users
JOIN users_roles ON users.uid = users_roles.uid
WHERE mail NOT LIKE '%@example.com' 
AND users_roles.rid =5
AND users.status =1
";

$result = db_query($query, $some_value);
    while ($row = db_fetch_object($result))
    { 
        $rows[] = array(
                    array('data' =&gt; $row-&gt;name, 'align' =&gt;'left'),
                    array('data' =&gt; $row-&gt;status, 'align' =&gt; 'left'),
                    array('data' =&gt; $row-&gt;rid, 'align' =&gt; 'center'),    
                    array('data' =&gt; $row-&gt;mail, 'align' =&gt; 'left'),    

        );
    }

    $table_attributes = array('id' =&gt; 'my_id_for_table', 'align' =&gt; 'center');
    $output .= theme('table', $header, $rows, $table_attributes);

    return $output; 


how can I correctly send my table via mail? I don't know (and I would like to have the drupal_mail function working to make some tests) if I should use $query or $result.

Thanx in advance.

Any ideas or help, please?
You need to implement hook_mail() in your custom module and then call drupal_mail() in your page callback function to get the result you want. You should save your table html in the $params array that gets delivered to hook_mail() and then set it as the $message['body'] value there (with additional html/data if needed). The linked tutorial and API pages should give you enough information and examples to work out the rest of the details.