Laravel 9 SymfonyMailer 错误 - 电子邮件必须具有“收件人”、“抄送”或“密件抄送”标头

Ank*_*nkh 6 php sendmail laravel symfony-mailer laravel-9

在使用 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));
    }
}
Run Code Online (Sandbox Code Playgroud)

可邮寄

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试过单独呈现邮件,并且有效。使用日志驱动程序,它可以工作,正如您所看到的,我什至尝试使用 mailable 类中的 withSymfonyMessage 方法绕过 Mail 外观,但没有任何效果。

是否有我缺少的配置或部分?我可以回去使用 SwiftMailer 而不会遇到 Laravel 9 的工作问题吗?

小智 5

使用->to()

return $this->from('theemail@gmail.com', 'Me')
            ->to($email, $name)
            ->view('emails.myemailview')
            ->with([
                'contact' => $this->contact
            ]);
Run Code Online (Sandbox Code Playgroud)