0

我使用自定义通知发送邮件,但主题未修改,发送邮件时为空。

代码通知:

<?php

namespace App\Notifier;

use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Notification\EmailNotificationInterface;
use Symfony\Component\Notifier\Message\EmailMessage;
use Symfony\Component\Notifier\Recipient\EmailRecipientInterface;
use Symfony\Component\Mime\RawMessage;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mime\Address;

class EmailNotification extends Notification implements EmailNotificationInterface
{
  public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage
  {
    $sender= new Address("test2@gmail.com");
    $recipient= new Address("test3@gmail.com");
    $envelope= new Envelope($sender, [$recipient]);
    $message = new RawMessage('bonjour test');   
    $email =new EmailMessage($message, $envelope);
    return $email;     
  }
}

代码控制器:

#[Route('/', name: 'app.index', methods:'GET')]
public function index(NotifierInterface $notifier, EmailNotification $emailNotification): Response
{       
  $recipient = new Recipient('test@gmail.com');
  $emailNotification->subject('hello hi');
  $notifier->send($emailNotification, $recipient);

  return $this->render('index/index.html.twig',[
    'message' => 'Hello test'
  ]);
}

问题是当我发送邮件时发现主题为空,但在我的控制器中我将主题设置为“hello hi”

谢谢

4

0 回答 0