public function sendMailMessages(MessageInterface
$message, AccountInterface
$sender) { // Clone the sender, as we make changes to mail and name properties.
$sender_cloned =
clone $this->userStorage->
load($sender->
id());
$params =
[];
$current_langcode =
$this->languageManager->
getCurrentLanguage()->
getId();
$recipient_langcode =
$this->languageManager->
getDefaultLanguage()->
getId();
$contact_form =
$message->
getContactForm();
if ($sender_cloned->
isAnonymous()) { // At this point, $sender contains an anonymous user, so we need to take
// over the submitted form values.
$sender_cloned->name =
$message->
getSenderName();
$sender_cloned->mail =
$message->
getSenderMail();
// For the email message, clarify that the sender name is not verified; it
// could potentially clash with a username on this site.
$sender_cloned->name =
$this->
t('@name (not verified)',
['@name' =>
$message->
getSenderName()]);
} // Build email parameters.
$params['contact_message'
] =
$message;
$params['sender'
] =
$sender_cloned;