v2board/app/Http/Controllers/Admin/MailController.php

41 lines
1.1 KiB
PHP
Raw Normal View History

2019-12-30 22:40:39 +08:00
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\MailSend;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Jobs\SendEmail;
class MailController extends Controller
{
public function send (MailSend $request) {
2019-12-31 01:04:55 +08:00
if ($request->input('type') == 2 && empty($request->input('receiver'))) {
2019-12-30 22:40:39 +08:00
abort(500, '收件人不能为空');
}
2019-12-30 22:52:02 +08:00
if ($request->input('receiver')) {
2019-12-30 22:40:39 +08:00
$users = User::whereIn('id', $recevicer)->get();
} else {
$users = User::all();
}
foreach ($users as $user) {
SendEmail::dispatch([
'email' => $user->email,
2019-12-30 22:45:10 +08:00
'subject' => $request->input('subject'),
2019-12-30 22:52:02 +08:00
'template_name' => 'mail.sendEmailCustom',
2019-12-30 22:40:39 +08:00
'template_value' => [
'name' => config('v2board.app_name', 'V2Board'),
'url' => config('v2board.app_url'),
2019-12-30 22:45:10 +08:00
'content' => $request->input('content')
2019-12-30 22:40:39 +08:00
]
]);
}
2019-12-30 22:45:42 +08:00
return response([
'data' => true
]);
2019-12-30 22:40:39 +08:00
}
}