Commerce order mail is empty for anonymous users In the function below, there is the problem of sending email to anonymous users, the email sending only for users logged and to complete checkout and payment.

I get the following error message:

Error sending e-mail (from admin@mysite.com to ).


My Module:

function mymodule_commerce_checkout_complete($order){
            // send mails
            mymodule_send_order_emails($order);
    }


function mymodule_send_order_emails($order = NULL) {
    $module = 'mymodule';
    $key = 'my_message';
    $from = variable_get('site_mail', 'info@mysite.com');
    $language = language_default();
    $values['html'] = 'Html text value.';
    $params = $values;
    $send = TRUE;

    // load profile
    $profile = commerce_customer_profile_load($order-&gt;commerce_customer_billing[LANGUAGE_NONE][0]['profile_id']);

    // load user
    $user = user_load($order-&gt;uid);
    //$user-&gt;name;
    $to = $user-&gt;mail;

    $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
}
You have anonymous orders so your code doing the loading of the user account obviously wont work as they dont have a user account: 

 // load user
$user = user_load($order-&gt;uid);
//$user-&gt;name;
$to = $user-&gt;mail;


The above won't work for anonymous users as they don't have an account so the uid is always 0. I think the $order object has $order->mail to get the actual email address used on the order regardless if it was a full user or anonymous