Laravel 9 SymfonyMailer 错误 - 电子邮件必须包含 "To"、"Cc" 或 "Bcc" header
Laravel 9 SymfonyMailer error - An email must have a "To", "Cc", or "Bcc" header
将使用 Metronic 8 主题的 Laravel 8 项目更新到 Laravel 9 后,发送电子邮件时遇到问题。我没有更改任何与电子邮件相关的代码,但现在我在使用 Sendmail driver :
时遇到了这个错误
An email must have a "To", "Cc", or "Bcc" header.
{"userId":6,"exception":"[object]
(Symfony\Component\Mime\Exception\LogicException(code: 0): An
email must have a "To", "Cc", or "Bcc" header. at
/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;
}
}
我试过单独渲染邮件,效果很好。使用日志 driver,它有效,正如你所见,我什至尝试使用可邮寄 class 中的 withSymfonyMessage 方法绕过 Mail facade,但没有任何效果。
是否有我缺少的配置或部分?我可以回去使用 SwiftMailer 而不用担心 Laravel 9 工作吗?
使用->to()
return $this->from('theemail@gmail.com', 'Me')
->to($email, $name)
->view('emails.myemailview')
->with([
'contact' => $this->contact
]);
An email must have a "To", "Cc", or "Bcc" header. {"userId":6,"exception":"[object] (Symfony\Component\Mime\Exception\LogicException(code: 0): An email must have a "To", "Cc", or "Bcc" header. at /home/myhome/public_html/myproject.com/vendor/symfony/mime/Message.php:128)
如果缺少 to()
或者如果 to()
方法在您的 Mailable class
中收到一个空集合,您将得到上述异常
将使用 Metronic 8 主题的 Laravel 8 项目更新到 Laravel 9 后,发送电子邮件时遇到问题。我没有更改任何与电子邮件相关的代码,但现在我在使用 Sendmail driver :
时遇到了这个错误An email must have a "To", "Cc", or "Bcc" header. {"userId":6,"exception":"[object] (Symfony\Component\Mime\Exception\LogicException(code: 0): An email must have a "To", "Cc", or "Bcc" header. at /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;
}
}
我试过单独渲染邮件,效果很好。使用日志 driver,它有效,正如你所见,我什至尝试使用可邮寄 class 中的 withSymfonyMessage 方法绕过 Mail facade,但没有任何效果。
是否有我缺少的配置或部分?我可以回去使用 SwiftMailer 而不用担心 Laravel 9 工作吗?
使用->to()
return $this->from('theemail@gmail.com', 'Me')
->to($email, $name)
->view('emails.myemailview')
->with([
'contact' => $this->contact
]);
An email must have a "To", "Cc", or "Bcc" header. {"userId":6,"exception":"[object] (Symfony\Component\Mime\Exception\LogicException(code: 0): An email must have a "To", "Cc", or "Bcc" header. at /home/myhome/public_html/myproject.com/vendor/symfony/mime/Message.php:128)
如果缺少 to()
或者如果 to()
方法在您的 Mailable class