2017-02-10 33 views
1

symfony 2.3のバージョンを使用していて、fos_user設定で2つの異なるfrom_emailを設定したいのですが、どうすれば設定できますか?FOS_USER設定で2つの異なるfrom_emailを設定する

私は[email protected]を使用して登録、通常のユーザーの後にウェルカムメールを送信し、[email protected]

Plzをを使用してほかのユーザーウェルカムメールを送信したい任意の解決策を提案します。

+0

'通常のユーザーが' 何で、 '追加のユーザーが' 何ですか? – Vamsi

+0

2人のユーザーの間に違うのは、追加のユーザーです。通常のユーザーと比較していくつかの機能があります –

答えて

1

あなたは

例カスタムサービスを作成します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: 
    # ... 
    service: 
     mailer: app.custom_fos_user_mailer 

参考リンクカスタムメーラーを使用するfos_userの設定を更新:

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

+0

返信ありがとうございます。 CustomMailerサービスクラスを作成する場所 –

関連する問題