sending query results via email if this is my function:

&lt;?php
//dsm($query);


function customstatsB_menu() {
  $items['customstatsB'] = array(
    'title' =&gt; 'Maestros Inactivos + email',
    'page callback' =&gt; 'customstatsB_all',
    'access arguments' =&gt; array('access customstatsB content'),
    'type' =&gt; MENU_CALLBACK
  );
  return $items;
}
/**
* Valid permissions for this module
* @return array An array of valid permissions for the customstats module
 * No repetir permisos, este es únicamente un modulo, y cada query NO necesita permisos. PERMISOS A NIVEL MODULE x ROL.
 */

function customstatsB_perm() {
  return array('access customstatsB content');
} // function customstats_perm()

//return array('access customstats content', 'administer customstats');

function customstatsB_all() {

/**
 * MAESTROS INACTIVOS 
 */

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

  // get the links (no range limit here)
  $queryResult =  db_query($query);
  while ($links = db_fetch_object($queryResult)) {
    //$page_content .= l($links-&gt;name, 'node/'.$links-&gt;mail) . '&lt;br /&gt;';
    $page_content .= 
    l($links-&gt;name, 'mailto:'.$links-&gt;mail) . '&lt;br /&gt;';
  }

  // check to see if there was any content before
  // returning the page
  if ($page_content == '') {
    // let the user know there is no content to show
    $page_content = "No existe información para mostrar.";
  }

  return $page_content;
}

return array('access customstatsB content', 'administer customstatsB');

/**
 * Email configs 
 */




function customstatsB_mail($key, &amp;$message, $params)
  {
     $params = array(
        'subject' =&gt; t('SQL Results Tester'),
        'body' =&gt; t("Body of the email goes here"),
      );

      drupal_mail("customstatsB", "customstatsB_normal_mail", "my@mail.net", language_default(), $params, "admin@mysite.com");
      drupal_mail("customstatsB", "customstatsB_html_mail", "my@mail.net", language_default(), $params, "admin@mysite.com");
  }
      $language = $message['language'];
      switch ($key)
      {
           case 'customstats_normal_mail':
              $message['subject'] = t($params['subject'], $var, $language-&gt;language);
              $message['body'][] = $params['body'];
              break;
          case 'customstats_html_mail':

              $message['subject'] = t($params['subject'], $var, $language-&gt;language);

               $body = "&lt;html&gt;&lt;body&gt;
                  &lt;h2&gt;HTML Email Sample with Drupal&lt;/h2&gt;
                  &lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;
                  {$params['body']}
                  &lt;/body&gt;&lt;/html&gt;";
              $message['body'][] = $body;
              $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
              break;
      }
  }


and I am using hook_mail and drupal_mail to send an email, how should I insert the query results into the body of the mail?

Also, I have created pagecallbacks customstats1 to customstats15 via hook_menu and I need to send indivual mails when users visit each page independently. I have read a few tutorials but I haven't been able to do this.

Thanks in advance for your help.
You need to invoke hook_mail() to specify a 'body' parameter. It is a little confusing since it is two steps but well documented: http://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_mail/6

See 'example_notify()' and 'example_mail()' from the above link.

In your case yo need to call drupal_mail outside of your invocation of hook_mail. See below for an example. You can pass the body as in the $param when you call drupal_mail or you can edit it when you invoke hook_mail.

Be advised that this is not the best example since it would fire off an email any time somone visited that page, but I'm not sure where you are trying to call drupal_mail from:

$query = "
SELECT uid
FROM users
JOIN users_roles ON users.uid = users_roles.uid
WHERE mail NOT LIKE '%@mail.com' 
AND users_roles.rid =6
AND users.status =0
";


 // get the links (no range limit here)
  $queryResult =  db_query($query);
  while ($links = db_fetch_object($queryResult)) {
    $account = user_load($links-&gt;uid);
    $body = t('Message for %name', array('%name' =&gt; $links-&gt;name));
    $subject = t('New email!');
    $params = array('body' =&gt; $body, 'subject' =&gt; $subject);
    drupal_mail('customstats', 'html_mail', $account-&gt;mail, user_preferred_language($account), $params);  
    $page_content .= l($account-&gt;name, 'mailto:'.$account-&gt;mail) . '&lt;br /&gt;';
   }


  if ($page_content == '') {
    $page_content = "No existe información para mostrar.";
  }

  return $page_content;
}