Я пришел сюда, потому что у меня проблема с OVH и моим приложением symfony2, я не могу отправить почту с SwiftMailer. Для FOSUserBundle довольно проблематично сбросить пароль или активировать мою учетную запись после надписи. Поэтому я хочу использовать функцию MAIL
, реализованную в PHP, и выполнил документацию here. Таким образом, я создал свой класс MailerInterface.php
и класс Mailer.php
потому, что этот класс отправки почты с функцией sendEmailMessage
Symfony2 и FOSUserBundle: Override Mailer
Здесь вы можете увидеть, как я реализовал класс:
<?php
namespace MonApp\UserBundle\Mailer;
use FOS\UserBundle\Model\UserInterface;
interface MailerInterface
{
function sendConfirmationEmailMessage(UserInterface $user);
function sendResettingEmailMessage(UserInterface $user);
}
?>
И в Mailer.php
:
<?php
namespace MonApp\UserBundle\Mailer;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Routing\RouterInterface;
use FOS\UserBundle\Model\UserInterface;
use MonApp\UserBundle\Mailer\MailerInterface;
class Mailer implements MailerInterface
{
protected $mailerMonApp;
protected $router;
protected $templating;
protected $parameters;
public function __construct($mailerMonApp, RouterInterface $router, EngineInterface $templating, array $parameters) {
$this->mailerMonApp = $mailerMonApp;
$this->router = $router;
$this->templating = $templating;
$this->parameters = $parameters;
}
public function sendConfirmationEmailMessage(UserInterface $user) {
The function...
}
public function sendResettingEmailMessage(UserInterface $user) {
The function...
}
protected function sendEmailMessage($renderedTemplate, $fromEmail, $toEmail) {
$renderedLines = explode("\n", trim($renderedTemplate));
$subject = $renderedLines[0];
$body = implode("\n", array_slice($renderedLines, 1));
mail($toEmail, $subject, $body, '[email protected]');
}
}
Я добавил свой класс как сервис:
services:
monapp.mailer:
class: MonApp\UserBundle\Mailer\Mailer
И изменил config.yml
:
service:
mailer: monapp.mailer
Здесь ERROR
в Dev окр:
Warning: Missing argument 1 for MonApp\UserBundle\Mailer\Mailer::__construct(), called in /home/domaine/www/nomappli/app/cache/dev/appDevDebugProjectContainer.php on line 831 and defined in /home/domaine/www/nomappli/src/MonApp/UserBundle/Mailer/Mailer.php line 29
Моей проблема: Когда я приезжаю на моей странице сброса пароля, я пишу свой псевдо и после проверки из форме я получил белую страницу. Я думаю, что я называю class and use
, используемый в учебнике, поэтому я не понимаю свою проблему, возможно, я забыл использовать?
Благодаря
EDIT Здесь ошибки журналы (спасибо Michael & Yann для помогли мне):
[2015-03-31 14:55:35] request.INFO: Matched route "fos_user_resetting_send_email" (parameters: "_controller": "FOS\UserBundle\Controller\ResettingController::sendEmailAction", "_route": "fos_user_resetting_send_email") [] []
[2015-03-31 14:55:35] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2015-03-31 14:55:35] request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "Unable to find template ""." at /home/nomappli/www/monapp/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 128 {"exception":"[object] (InvalidArgumentException: Unable to find template \"\". at /home/nomappli/www/monapp/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php:128, Twig_Error_Loader: Unable to find template \"\". at /home/nomappli/www/monapp/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php:106, InvalidArgumentException: Template name \"\" is not valid (format is \"bundle:section:template.format.engine\"). at /home/nomappli/www/monapp/app/cache/prod/classes.php:742)"} []
[2015-03-31 14:55:35] security.DEBUG: Write SecurityContext in the session [] []
Белая страница означает ошибку для меня ... Можете ли вы предоставить любой журнал? –
Я отредактировал мое сообщение, чтобы добавить ошибку. ошибка в DEV: Предупреждение: Отсутствует аргумент 1 для MonApp \ UserBundle \ Mailer \ Mailer :: __ construct(). – Remi