// Build email parameters.
$params['contact_message'
] =
$message;
$params['sender'
] =
$sender_cloned;
if (!
$message->
isPersonal()) { // Send to the form recipient(s), using the site's default language.
$params['contact_form'
] =
$contact_form;
$to =
implode(', ',
$contact_form->
getRecipients());
} elseif ($recipient =
$message->
getPersonalRecipient()) { // Send to the user in the user's preferred language.
$to =
$recipient->
getEmail();
$recipient_langcode =
$recipient->
getPreferredLangcode();
$params['recipient'
] =
$recipient;
} else { throw new MailHandlerException('Unable to determine message recipient'
);
} // Send email to the recipient(s).
$key_prefix =
$message->
isPersonal() ? 'user' : 'page';