我是 Laravel 8 的新手,正在尝试使用 Laravel 8 的邮件功能,但有几个问题需要您的专家指导来解决这个问题。基本上,我必须使用 Laravel 8 通过 Outlook 创建一个警报系统,但有一些限制:
至于现在,这就是我所做的:
.env 文件
MAIL_DRIVER=?
MAIL_HOST=xx.xx.xx.xx
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=tls
配置/mail.php
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'xx.xx.xx.xx'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
'ses' => [
'transport' => 'ses',
],
'mailgun' => [
'transport' => 'mailgun',
],
'postmark' => [
'transport' => 'postmark',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -t -i'),
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
'failover' => [
'transport' => 'failover',
'mailers' => [
'smtp',
'log',
],
],
],
app/Mail/Auditalert.php
<?php
namespace App\Mail;
use App\Models\AuditModule\History;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class Auditalert extends Mailable
{
public $findPending;
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(History $findPending)
{
$this->findPending = $findPending;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('emails.audit-alert');
}
}
应用程序/控制台/命令/CheckPendingStatus.php
<?php
namespace App\Console\Commands;
use App\Models\AuditModule\History;
use App\Mail\Auditalert;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
class CheckPendingAudit extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check:audit-status';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check the status of latest form either Pending or not.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$findPending = History::latest()->first();
try{
if($findPending->status == 'Pending'){
//Sender email
Mail::to('[email protected]')
->cc(['[email protected]', '[email protected]'])
->send(new Auditalert($findPending));
//Just to notify if email success...will delete later after testing
$this->info('Email notification sent successfully!');
}else{
//Just to notify if no email success...will delete later after testing
$this->info('No email notification sent!');
}
}catch(\Exception $e){
throw new \Exception('Failed email notification!' .$e->getMessage());
}
}
}
和我的观点
@component('mail::message')
Welcome to SydDevel
This is a gentle reminder to update the Work Place Inspection Form for this quater!
@component('mail::button', ['url' => 'xx.xx.xx.xx/sysdevel/'])
Visit Site
@endcomponent
Thank you,<br>
{{ config('app.name') }}
@endcomponent
有人可以帮我做什么吗?我已经尝试了一个月