0

在使用 Metronic 8 主题将 Laravel 8 项目更新到 Laravel 9 后,我在发送电子邮件时遇到问题。我没有更改与电子邮件相关的任何代码,但现在使用 Sendmail 驱动程序出现此错误:

电子邮件必须有“收件人”、“抄送”或“密送”标题。{"userId":6,"exception":"[object] (Symfony\Component\Mime\Exception\LogicException(code: 0):电子邮件必须有“To”、“Cc”或“Bcc”标头。在/home/myhome/public_html/myproject.com/vendor/symfony/mime/Message.php:128)

控制器

class MyController extends Controller
{
    public function activate($id)
    {
        $mymodel = MyModel::find($id);

        $contact = Contact::where('mymodel_id', $mymodel->id)->first();
        Mail::to($contact->email)->send(new MyMail($contact));
    }
}

可邮寄

class MailActive extends Mailable
{
    use Queueable, SerializesModels;

    protected $contact;

    public function __construct(Contact $contact)
    {
        $this->contact = $contact;
    }

    public function build()
    {
        return $this->from('theemail@gmail.com', 'Me')
            ->view('emails.myemailview')
            ->with([
                'contact' => $this->contact
            ]);

        // $this->withSymfonyMessage(function (Email $message) {
        //     $message->getHeaders()->addTextHeader(
        //         'addAddress', 'theemail@gmail.com'
        //     );
        // });

        // return $this;
    }
}

我试过单独渲染邮件,它可以工作。使用日志驱动程序,它可以工作,并且如您所见,我什至尝试使用可邮寄类中的 withSymfonyMessage 方法绕过 Mail 门面,但没有任何效果。

是否有我缺少的配置或部分?我可以不用 SwiftMailer 回去让 Laravel 9 正常工作吗?

4

1 回答 1

3

使用->to()

return $this->from('theemail@gmail.com', 'Me')
            ->to($email, $name)
            ->view('emails.myemailview')
            ->with([
                'contact' => $this->contact
            ]);
于 2022-02-17T11:25:46.517 回答