简体   繁体   English

在 FOS_USER 配置中设置两个不同的 from_email

[英]Setup two different from_email in FOS_USER configuration

I'm using symfony 2.3 version and I want to configure two different from_email in fos_user configuration how is it possible and where to set my configuration.我正在使用 symfony 2.3 版本,我想在 fos_user 配置中配置两个不同的 from_email 怎么可能以及在哪里设置我的配置。

I want to send welcome email after registration normal user using normaluser@gmail.com and send addition user welcome email using additionaluser@gmail.com我想用注册普通用户后,发送欢迎电子邮件normaluser@gmail.com和使用发送另外用户的欢迎电子邮件additionaluser@gmail.com

Plz suggest any solution.请建议任何解决方案。

You can do it by Using A Custom Mailer.您可以通过使用自定义邮件程序来完成。

Create a custom service创建自定义服务

Example:例子:

<?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());
    }

}

and update the fos_user configuration to use your custom mailer并更新 fos_user 配置以使用您的自定义邮件程序

fos_user:
    # ...
    service:
        mailer: app.custom_fos_user_mailer

Reference links:参考链接:

http://symfony.com/doc/current/bundles/FOSUserBundle/emails.html#using-a-custom-mailer https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Mailer/Mailer.php http://symfony.com/doc/current/bundles/FOSUserBundle/emails.html#using-a-custom-mailer https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Mailer/Mailer.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM