I want to sent email on a specific language regarding of the web language.
For example when the user register he has the possibility to select a language for example English - en, Italian - it, German - de and french - fr.
The website is multilingual, so what i wanna do is that when a user fills a form for example the contact form, and after he submits the form an e-mail is sent to him.
So lets assume that he has selected Italian as language of the website, but when he was registered he had selected English. So the E-mail should be sent on English even though the site is in Italian.
Emails are translated through __() function of cakephp using .pot files.
Email Template is this:
contact_us_user
<h2 style="color: #ee2424;">
<?php
echo __('SITENAME');
?>
</h2>
<?php
echo "<h2 style='text-align: left;'>";
if (isset($firstname) && isset($lastname) && isset($title)) {
echo __('Hello <span style="color: #ee2424;"> %s %s</span>.', $firstname, $lastname);
} else {
echo __('Hello');
}
echo "</h2>";
echo __('Thank you for contacting us!');
echo "<br />";
echo __('We will take a look to your <strong>reservation enquiry</strong> and we will get back to you with a booking quote');
echo "<br />";
echo "<hr />";
echo __('<p>Thanks and Regards.</p>');
?>
And the function that send the e-mail is this:
/* SEND MESSAGE TO THE USER */
$layout = 'default';
$template = 'contact_us_user';
$subject = __('TEST');
$title_for_layout = __('Contact US');
$viewVars = array(
"firstname" => $this->request->data['Contact']['name'],
"lastname" => $this->request->data['Contact']['surname'],
);
if(isset($this->request->data['Contact']['email']) && !empty($this->request->data['Contact']['email']) && trim($this->request->data['Contact']['email'])!='') {
$this->__sendEmail($this->request->data['Contact']['email'], $subject, $template, $viewVars, $layout, $title_for_layout);
}
And the method is as bellow:
/**
* send E-mail method
*
* @return boolean
*/
public function __sendEmail($emailTo, $subject = 'Email', $template = 'default', $viewVars, $layout = 'default', $title_for_layout = 'test') {
$this->set('title_for_layout', $title_for_layout);
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$Email->template($template, $layout)
->emailFormat('html')
->viewVars($viewVars)
->from(array('info@sitename.com'=>'sitename.com'))
->to($emailTo)
->subject($subject);
return $Email->send();
}
So what I am asking is that is there a way or parameter to pass to email to indicate in which language I want email to be sent.
Something like: $language = 'en';
My Cakephp version is: 2.5.6
Thanks in advance.