我正在尝试使用symfony 4.3中的new mailer component发送邮件,但是如果尝试实现,则会收到以下异常:
试图调用类“ Symfony \ Component \ Mime \ Header \ Headers”中名为“ getAll”的未定义方法。
堆栈跟踪:
Symfony\Component\Debug\Exception\UndefinedMethodException:
Attempted to call an undefined method named "getAll" of class "Symfony\Component\Mime\Header\Headers".
at vendor/symfony/mailer/DelayedSmtpEnvelope.php:76
at Symfony\Component\Mailer\DelayedSmtpEnvelope::getRecipientsFromHeaders(object(Headers))
(vendor/symfony/mailer/DelayedSmtpEnvelope.php:69)
at Symfony\Component\Mailer\DelayedSmtpEnvelope->getRecipients()
(vendor/symfony/mailer/Transport/AbstractTransport.php:75)
at Symfony\Component\Mailer\Transport\AbstractTransport->send(object(Email), object(DelayedSmtpEnvelope))
(vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:115)
at Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->send(object(Email), null)
(vendor/symfony/mailer/Mailer.php:38)
at Symfony\Component\Mailer\Mailer->send(object(Email))
(src/Controller/TicketController.php:209)
at App\Controller\TicketController->sendEmail('example@mail.com', 'example@mail.com', null)
(src/Controller/TicketController.php:193)
at App\Controller\TicketController->handleRequest(object(Request))
(src/Controller/TicketController.php:51)
at App\Controller\TicketController->createGeneral(object(Request))
(vendor/symfony/http-kernel/HttpKernel.php:151)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor/symfony/http-kernel/HttpKernel.php:68)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor/symfony/http-kernel/Kernel.php:198)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(index.php/:25)
到目前为止,我的代码:
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
class TicketController extends AbstractController
{
private $mailer;
public function __construct(MailerInterface $mailer)
{
$this->mailer = $mailer;
}
[...]
public function sendEmail($ticketRecipient, $responsibilityRecipient)
{
$email = (new Email())
->from('exampleSender@mail.com')
->to($ticketRecipient, $responsibilityRecipient)
->subject('example subject')
->text('example text')
->html('<p>todo Twig Integration<p/>');
try {
$this->mailer->send($email);
} catch (TransportExceptionInterface $e) {
}
}
}
我想念什么吗?