1 回答
TA贡献1869条经验 获得超4个赞
您需要单独发送每个用户的电子邮件,将用户数据传递到您创建的可邮寄类。
<?php
namespace App\Mail;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class MyCustomUserMail extends Mailable
{
use Queueable, SerializesModels;
public $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function build()
{
return $this->view('emails.users.my_custom_user_view');
}
}
在您的自定义视图中:
{{ $user->name }}
发送电子邮件:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Mail\MyCustomUserMail;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
class UserController extends Controller
{
public function doSomething()
{
$users = User::all();
$users->each(function ($user) {
Mail::to($user->email)->send(new MyCustomUserMail($user));
});
}
}
- 1 回答
- 0 关注
- 98 浏览
添加回答
举报