【发布时间】:2017-11-27 09:44:17
【问题描述】:
在我的 symfony 项目中,我尝试配置一个电子邮件控制器,但没有成功。
services.yml
emailController:
class: AppBundle\Controller\emailController
public: true
arguments:
$mailer: '@mailer'
emailController.php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use FOS\UserBundle\FOSUserEvents;
use Doctrine\ORM\EntityManagerInterface;
class emailController extends Controller
{
protected $mailer;
function __construct(\Swift_Mailer $mailer) {
$this->mailer = $mailer;
}
public function sendMail($email){
$message = (new \Swift_Message())
->setSubject('send mail')
->setFrom('xx@yy.com')
->setTo($email)
->setBody('TEST')
->setContentType("text/html");
$this->mailer->send($message);
return 1;
}
}
Symfony 返回此消息:
可捕获的致命错误:参数 1 传递给 AppBundle\Controller\emailController::__construct() 必须是 Swift_Mailer 的实例,没有给出,
我尝试了一些配置和选项,但没有成功
【问题讨论】:
标签: php symfony swiftmailer