简体   繁体   中英

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.

I want to send welcome email after registration normal user using normaluser@gmail.com and send addition user welcome email using 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:
    # ...
    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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