I can't get it working. What am I doing wrong?

$name = $form_state['values']['name'];
$rname = $form_state['values']['rname'];
$email = $form_state['values']['email'];
$message = $form_state['values']['message'];

$params = array('current_conditions' => $data);
$message = drupal_mail('wow', rand(0, 999), $email, $language, $params, FALSE);
$message['body'][] = 'test';
// Only add to the spool if sending was not canceled.
if ($message['send']) {

2 Answers 2


The last parameter you are passing to drupal_mail() is FALSE. That parameter is telling the function if sending the mail. The documentation describes the parameter as follows:

$send: If TRUE, drupal_mail() will call drupal_mail_system()->mail() to deliver the message, and store the result in $message['result']. Modules implementing hook_mail_alter() may cancel sending by setting $message['send'] to FALSE.

As its default value is TRUE, just leave out that parameter, and the mail will be send, if other modules don't set $message['send'] to FALSE.


Your code only prepares message for sending it later. Example of sending e-mail immediately:


$my_module = 'foo';
$my_mail_token = 'bar';
$from = variable_get('system_mail', '[email protected]');
$message = array(
  'id' => $my_module . '_' . $my_mail_token,
  'to' => '[email protected]',
  'subject' => 'test',
  'body' => array(
    'line 1',
    'line 2',
  'headers' => array(
    'From' => $from,
    'Sender' => $from,
    'Return-Path' => $from,
$system = drupal_mail_system($my_module, $my_mail_token);
// The format function must be called before calling the mail function. 
$message = $system->format($message);
if ($system->mail($message)) {
  // Success.
else {
  // Failure.


Edit: changed to better example

  • 1
    drupal_mail() calls drupal_mail_system(). There is no reason to call it again after.
    – apaderno
    Mar 27, 2013 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.