I'm getting this error while developing a module:

Warning: Invalid arguments passed in DefaultMailSystem->format() (line 23 /modules/system/system.mail.inc)

here's my code:

function mymod_mail($key, &$message, $params) {
    switch ($key) {
        case 'job_mail':
            $message['subject'] = 'mysubject';
            $message['body'][] = 'test';

I googled it normaly this happens when $message['body'] is defined like this: $message['body'] = 'test'; instead of $message['body'][] = 'test';

And then I've got the following code to call the above hook_mail()

function mymod_send_mail($vacancies, $user) {
    // specify module name and template key for hook_mail
    $module = 'mymod';
    $key = 'job_mail';

    // Specify to and from addressses.
    $to = 'my@email.com'; // user email TODO get user email based on $uid
    $language = language_default();
    $params = array(
        'username' => $user->name, 
        'sitename' => variable_get('site_name', 'Drupal'), 
    $from = variable_get('site_mail', 'default@email.com');
    $send = TRUE; // defaul = TRUE can be set to FALSE to not actually send the mail and only generate it.
    drupal_mail($module, $key, $to, $language, $params, $from, $send );

I've put a debug() in system.mail.inc above the implode function but that showed my message $message['body'] was not an array ( $message['body'][] ) anymore.

Also when I put a debug on the result of the drupal_mail function I see that my subject is set but the body is empty.

  • 2
    Perhaps try with $language = language_default('language'); instead? May 21, 2013 at 9:06

1 Answer 1


I fixed it by using:

$language = user_preferred_language($user);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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