Php laravel mail如何正确实施到系统中
因此,我尝试实现一个命令,该命令通过每天进行检查的命令通知所有订阅事件的用户。我正在阅读,所以有一个关于订单系统的例子,他们用这种代码发送邮件Php laravel mail如何正确实施到系统中,php,laravel,email,Php,Laravel,Email,因此,我尝试实现一个命令,该命令通过每天进行检查的命令通知所有订阅事件的用户。我正在阅读,所以有一个关于订单系统的例子,他们用这种代码发送邮件 foreach (['taylor@example.com', 'dries@example.com'] as $recipient) { Mail::to($recipient)->send(new OrderShipped($order)); } 它的外观将接收循环中的电子邮件,然后向该地址发送电子邮件。 所以我制作了一个邮件类php
foreach (['taylor@example.com', 'dries@example.com'] as $recipient) {
Mail::to($recipient)->send(new OrderShipped($order));
}
它的外观将接收循环中的电子邮件,然后向该地址发送电子邮件。
所以我制作了一个邮件类php artisan make:mail NotifyUserOfEvents
我在哪里编写了此代码
<?php
namespace App\Mail;
use App\Event;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NotifyUserOfEvents extends Mailable
{
use Queueable, SerializesModels;
protected $event;
public function __construct(Event $event)
{
$this->event = $event;
}
public function build()
{
return $this->view('mails.NotifyUserOfEvents')
->with([
'name' => $this->event->name,
'date' => $this->event->settings->start_date,
]);
}
}
您必须向
send
函数传递NotifyUserOfEvents
的对象,而不是事件
对象
试试这个:
Mail::to($user->email)->send(new NotifyUserOfEvents($event))
您必须将NotifyUserOfEvents
的对象传递给send
函数,而不是事件
对象
试试这个:
Mail::to($user->email)->send(new NotifyUserOfEvents($event))代码>$applicationName=null;
$subject=“为“$applicationName”收到的申请;
$emailParameters=[“applicationName”=>$applicationName,“proposerName”=>$proposerName,“seconderName”=>$seconderName];
尝试
{
Mail::send('emails.application', $emailParameters, function($message) use ($applicantName, $subject){
$message->to(['test@gmail.com','test@gamil.com'], " Test Email Function ")
->subject($subject);
});
} catch (Exception $ex){ Log::error("UserController".$ex->getMessage());
}
$applicationName=null;
$subject=“为“$applicationName”收到的申请;
$emailParameters=[“applicationName”=>$applicationName,“proposerName”=>$proposerName,“seconderName”=>$seconderName];
尝试
{
Mail::send('emails.application', $emailParameters, function($message) use ($applicantName, $subject){
$message->to(['test@gmail.com','test@gamil.com'], " Test Email Function ")
->subject($subject);
});
} catch (Exception $ex){ Log::error("UserController".$ex->getMessage());
}
关于这一行:
Mail::to($user->email)->send(new Event($event));
您正在创建一个新的事件
并将另一个事件
传递给构造函数……您可能从未定义一个构造函数,该构造函数将事件
作为第一个参数接受。
但是尽管如此,这样做有什么意义呢?要想Mail::send
,你必须传递一个Mailable
,而不是一个事件,我很确定你不需要一个新的事件,所以我相信你会想这样做:
use App\Mail\NotifyUserOfEvents; // or whatever namespace you have to the mail
Mail::to($user->email)->send(new NotifyUserOfEvents($event));
关于这一行:
Mail::to($user->email)->send(new Event($event));
您正在创建一个新的事件
并将另一个事件
传递给构造函数……您可能从未定义一个构造函数,该构造函数将事件
作为第一个参数接受。
但是尽管如此,这样做有什么意义呢?要想Mail::send
,你必须传递一个Mailable
,而不是一个事件,我很确定你不需要一个新的事件,所以我相信你会想这样做:
use App\Mail\NotifyUserOfEvents; // or whatever namespace you have to the mail
Mail::to($user->email)->send(new NotifyUserOfEvents($event));
然后我得到另一个错误Class App\Event包含8个抽象方法,因此必须声明为抽象或实现其余方法(illumb\Contracts\Mail\Mailable::send,illumb\Contracts\Mail\Mailable::queue,illumb\Contracts\Mail\Mailable::later,…)
然后它生成如下函数:公共函数send($mailer){//TODO:Implement send()方法。}
例如,我需要在send()中实现什么functions@HashtagForgotName确保使用App\Models\Events
(因此您的模型)在NotifyUserOfEvents中,否则Laravel将使用事件的别名,这是另一个整体world@HashtagForgotName当然,请张贴整个文件,所有的“使用…”不仅仅是类本身更新了帖子,我还导入了我使用的想法,建议我生成的类必须声明为抽象的或实现方法“bcc”、“cc”、“to”、“later”、“locale”、“mailer”、“queue”、“send”
什么将生成这些函数,但它会在这些函数上出错functions@HashtagForgotName事件不必实现Mailable然后我得到另一个错误Class App\Event包含8个抽象方法,因此必须声明为抽象方法或实现其余方法(Illumb\Contracts\Mail\Mailable::send,Illumb\Contracts\Mail\Mailable::queue,Illumb\Contracts\Mail\Mailable::later,…)
然后它生成如下函数:公共函数send($mailer){//TODO:Implement send()方法。}
例如,我需要在send()中实现什么functions@HashtagForgotName确保使用App\Models\Events
(因此您的模型)在NotifyUserOfEvents中,否则Laravel将使用事件的别名,这是另一个整体world@HashtagForgotName当然,请张贴整个文件,所有的“使用…”不仅仅是类本身更新了帖子,我还导入了我使用的想法,建议我生成的类必须声明为抽象的或实现方法“bcc”、“cc”、“to”、“later”、“locale”、“mailer”、“queue”、“send”
什么将生成这些函数,但它会在这些函数上出错functions@HashtagForgotName事件不必实现Mailable