donglu2761 2014-07-25 13:27
浏览 35


I'm using the mailing library from zend framework 2, and also I'm using the translator functionality. But the translations only work inside the template .phtml, and not work in the service function for send the email, for example in translating the subject of the email. This is my code inside my service function to send an email:

$mailFactory = $this->getDependency('mail');
$viewModel = new ViewModel(array(
    'variable' => $x
$message = $mailFactory->prepareMessage($viewModel);
    ->addHeaderLine('MIME-Version', '1.0')
    ->addHeaderLine('Content-type', 'text/html; charset=UTF-8');
$message->setSubject($this->translate('Recover your password'));
$message->addTo($email, $fullname);
$transport = $mailFactory->getTransport();

return $transport->send($message);

The function $this->translate('...') calls to a class that call this code: return $this->translator->translate($text), this works well in all my application, but only works wrong when I send any email (with an exception of the template.phtml, inside this file the translator works well). All my mails received, have the subject in english (not translated) and the content in spanish (translated)

  • 写回答

1条回答 默认 最新


      相关推荐 更多相似问题


      • ¥15 vivado如何支持多维打包数组模式
      • ¥15 请问第13题到底应该怎么做
      • ¥15 stable diffusion报错问题
      • ¥20 数据可视化综合运用 导入npz文件以及读取内容
      • ¥15 倒计时汇编语言RTC实时时钟
      • ¥15 CCS安装出现Failed to create the part's controls
      • ¥15 请问有digital Fortran编译器吗
      • ¥15 用cst怎么仿真同轴馈线
      • ¥15 如何在lammps中添加气液边界条件?
      • ¥20 具有每日记账功能的简易日历程序