Why this code doesn't send an email with drupal_email()? I am developing a Drupal 6 module that should send an email after a form is submitted. So far, I wrote the following code.

function mailform_mail($key, &amp;$message, $params) {
  $headers = array(
    'MIME-Version' =&gt; '1.0',
    'Content-Type' =&gt; 'text/html; charset=UTF-8; format=flowed',
    'Content-Transfer-Encoding' =&gt; '8Bit',
    'X-Mailer' =&gt; 'Drupal'
  );

  foreach ($headers as $key =&gt; $value) {
    $message['headers'][$key] = $value;
  }
  $message['subject'] = $params['subject'];
  $message['body'] = $params['body'];
}

/**
 * Form submission handler.
 */
function mailform_form_submit($form, &amp;$form_state) {
  $valid_email = $form_state['values']['email'];
  $subject = $form_state['values']['Subject'];
  $body = $form_state['values']['body'];
  $params = array(
    'email'=&gt; $valid_email,
    'body' =&gt; $body,
    'subject' =&gt; $subject,
  );

 // The first argument of drupal_mail() function must match the first part of the hook_mail function.
 // Therefore the first argument is  'mailform_form' and the the mail hook is 'mailform_form_mail'
 // For more infoormation see:
 // - http://api.drupal.org/api/function/drupal_mail/6
 // - http://api.drupal.org/api/function/hook_mail/6
 if (drupal_mail('mailform','reply', $valid_email, language_default(), $params, $from, TRUE) {
    drupal_set_message('An email has been sent to ' . $valid_email);
  }
  else {
    drupal_set_message('There was an error sending your email');
  }
}


Using this code, I can get the values after a form is submitted, but the mail is not sent out.

Is there anything wrong with the code? The module machine name is mailform.
The answer's in your comments

//Therefore the first argument is  'mailform_form'


But you're using the string mailform as the first argument.

If your module is called mailform_form as your comments suggest, use this code:

drupal_mail('mailform_form','some_mail_key', $valid_email, language_default(), $params, $from, TRUE)


If it's named mailform, use your original call to drupal_mail, but change the name of your hook function to the correct one:

function mailform_mail($key, &amp;$message, $params) {