laravel - 如何在控制器 laravel 邮件上添加更多参数
问题描述
我想使用 Laravel 发送电子邮件并使用此代码成功
Mail::to($email)->send(new SendMail($name))
现在我想用这段代码发送更多参数,比如主题,但是没有用。没有错误消息,但未发送电子邮件。
Mail::send(new SendMail($name function($message) use ($email){
$message->to($email)->subject('Verify your Account');
}));
有什么建议么?提前致谢!
解决方案
你可以使用类似的东西
$template = 'view.email';
$paramets = ['data'=>$data];//Your to value to print in email
$email = 'to@email.com'// to email
$cc = 'cc@email.com' // or null
$toName = 'John Doe' // or null
$subject = 'Verify your Account';
Mail::send($template, $parameters, function($message) use($email,$cc,$toName,$subject) {
$message->from(env('sender'), env('nameSender'));
if($cc) $message->cc($cc);
$message->to($email, $toName)
->subject($subject);
});
我正在使用通用方法。所以我可以用这个方法来处理我需要发送的所有电子邮件
推荐阅读
- java - Java中如何传递方法参数?
- laravel - Vue,在唯一名称上选择表单而不是模型名称“post.body”
- image-processing - 使用 Tesseract 从小图像中读取日期
- flutter - 如何在 Flutter 中使用增强现实?有人可以推荐我任何课程或视频吗?
- python - 如何在常规 chrome 而不是 chromedriver 中运行 selenium 代码?
- postgresql - MAX(COUNT(...)) - 错误:不能嵌套调用聚合函数
- javascript - 是否可以在不同的系统/浏览器上具有相同 html 元素的不同 ID 属性?
- asynchronous - 我应该在服务器上的 WEB API 中使用 async/await 吗?
- javascript - 从 SQL Server 获取数据后重置记录集 - Angular
- postgresql - 我应该如何在我的 Postgres 数据库设计中处理父用户和子用户?