How do i fix Invalid arguments passed in DefaultMailSystem->format() (line 23 system.mail.inc 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, &amp;$message, $params) {
    switch ($key) {
        case 'job_mail':
            $message['subject'] = 'mysubject';
            $message['body'][] = 'test';
            break;
    }
}


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' =&gt; $user-&gt;name, 
        'sitename' =&gt; 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.
I fixed it by using:

$language = user_preferred_language($user);