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, &$message, $params) {
  $headers = array(
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer' => 'Drupal'

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

 * Form submission handler.
function mailform_form_submit($form, &$form_state) {
  $valid_email = $form_state['values']['email'];
  $subject = $form_state['values']['Subject'];
  $body = $form_state['values']['body'];
  $params = array(
    'email'=> $valid_email,
    'body' => $body,
    'subject' => $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.

Go to Source of this post
Author Of this post: Rahman
Title Of post: Why this code doesn’t send an email with drupal_email()?
Author Link: {authorlink}