我使用的是symfony 2.3版本,我想在fos_user配置中配置两个不同的from_email,如何设置我的配置。
我希望在使用 normaluser@gmail.com 注册普通用户后发送欢迎电子邮件,并使用 additionaluser@gmail.com
发送其他用户欢迎电子邮件Plz建议任何解决方案。
答案 0 :(得分:1)
创建自定义服务
示例:
<?php
namespace AppBundle\Mailer;
// implement all the needed methods
class CustomMailer implements MailerInterface
{
public function sendConfirmationEmailMessage(UserInterface $user)
{
$template = $this->parameters['confirmation.template'];
$url = $this->router->generate('fos_user_registration_confirm', array('token' => $user->getConfirmationToken()), UrlGeneratorInterface::ABSOLUTE_URL);
$rendered = $this->templating->render($template, array(
'user' => $user,
'confirmationUrl' => $url,
));
// implement the logic that decides which from_email to use
// change the from_email accordingly
$this->sendEmailMessage($rendered, $this->parameters['from_email']['confirmation'], (string) $user->getEmail());
}
}
并更新fos_user配置以使用您的自定义邮件程序
fos_user:
# ...
service:
mailer: app.custom_fos_user_mailer
参考链接:
http://symfony.com/doc/current/bundles/FOSUserBundle/emails.html#using-a-custom-mailer https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Mailer/Mailer.php