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 [email protected] 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', '[email protected]');
$language = language_default();
$values['html'] = 'Html text value.';
$params = $values;
$send = TRUE;
// load profile
$profile = commerce_customer_profile_load($order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id']);
// load user
$user = user_load($order->uid);
//$user->name;
$to = $user->mail;
$result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
}