增加测试邮件

This commit is contained in:
Wisp X 2022-02-14 14:35:04 +08:00
parent 0e996b579d
commit 8c80e70696
5 changed files with 51 additions and 0 deletions

View File

@ -3,11 +3,13 @@
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Mail\Test;
use App\Models\Config;
use App\Utils;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Mail;
use Illuminate\View\View;
class SettingController extends Controller
@ -26,4 +28,14 @@ class SettingController extends Controller
Cache::flush();
return $this->success('保存成功');
}
public function mailTest(Request $request): Response
{
try {
Mail::to($request->post('email'))->send(new Test());
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
return $this->success('发送成功');
}
}

View File

@ -1333,6 +1333,10 @@ select {
--tw-bg-opacity: 1;
background-color: rgb(234 179 8 / var(--tw-bg-opacity));
}
.bg-yellow-200 {
--tw-bg-opacity: 1;
background-color: rgb(254 240 138 / var(--tw-bg-opacity));
}
.bg-opacity-75 {
--tw-bg-opacity: 0.75;
}

View File

@ -118,6 +118,7 @@
<input type="hidden" name="mail[mailers][smtp][transport]" value="smtp">
<div class="text-right">
<x-button type="button" id="mail-test" class="bg-yellow-500">测试</x-button>
<x-button type="submit">保存更改</x-button>
</div>
</form>
@ -146,6 +147,36 @@
toastr[response.data.status ? 'success' : 'error'](response.data.message)
});
});
$('#mail-test').click(function () {
Swal.fire({
title: '请输入接收测试邮件的邮箱',
input: 'text',
inputValue: '',
inputAttributes: {
type: 'email',
autocapitalize: 'off'
},
showCancelButton: true,
confirmButtonText: '确认',
showLoaderOnConfirm: true,
preConfirm: (value) => {
return axios.post('{{ route('admin.settings.mail.test') }}', {
email: value,
}).then(response => {
if (! response.data.status) {
throw new Error(response.data.message)
}
return response.data;
}).catch(error => Swal.showValidationMessage(error));
},
allowOutsideClick: () => !Swal.isLoading()
}).then((result) => {
if (result.isConfirmed) {
toastr[result.value.status ? 'success' : 'warning'](result.value.message);
}
})
});
</script>
@endpush

View File

@ -0,0 +1,3 @@
<p>
您好,这是一封来自 {{ \App\Utils::config(\App\Enums\ConfigKey::SiteName) }} 的测试邮件,当您看到这封邮件后,说明邮件配置正确。如果不是您本人操作,请忽略。
</p>

View File

@ -84,6 +84,7 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth.admin']], function ()
Route::group(['prefix' => 'settings'], function () {
Route::get('', [AdminSettingController::class, 'index'])->name('admin.settings');
Route::put('save', [AdminSettingController::class, 'save'])->name('admin.settings.save');
Route::post('mail-test', [AdminSettingController::class, 'mailTest'])->name('admin.settings.mail.test');
});
});