在 FOS_USER 配置中设置两个不同的 from_email
Setup two different from_email in FOS_USER configuration
我正在使用 symfony 2.3 版本,我想在 fos_user 配置中配置两个不同的 from_email 怎么可能以及在哪里设置我的配置。
我想在注册普通用户后使用 normaluser@gmail.com 发送欢迎电子邮件,并使用 additionaluser@[=22 发送附加用户欢迎电子邮件=]
请提出任何解决方案。
你可以通过 Using A Custom Mailer.
创建自定义服务
示例:
<?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
我正在使用 symfony 2.3 版本,我想在 fos_user 配置中配置两个不同的 from_email 怎么可能以及在哪里设置我的配置。
我想在注册普通用户后使用 normaluser@gmail.com 发送欢迎电子邮件,并使用 additionaluser@[=22 发送附加用户欢迎电子邮件=]
请提出任何解决方案。
你可以通过 Using A Custom Mailer.
创建自定义服务
示例:
<?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