我正在使用Laravel 5.7从事工作(队列)。我已经将每个周末的电子邮件安排到工作表中。对于电子邮件计划程序,我已将所有电子邮件信息(例如,从,到,回复电子邮件地址)以及电子邮件正文存储到作业表中。
我在这里按工作类别添加了
use Dispatchable,
InteractsWithQueue,
Queueable,
SerializesModels;
protected $details;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct() {
$this->details = $details;
}
/**
* Execute the job.
*
* @return void
*/
public function handle() {
//
$payload = json_decode($event->job->getRawBody());
$data = unserialize($payload->data->command);
echo $data;
exit;
Mail::send(
['html' => 'emails.templates'], array('body' => $body, 'title' => $post_data['subject']), function($message) use ($post_data, $employee, $clientName, $docName, $filename) {
$message->to($post_data['email'], $clientName)->subject($post_data['subject']);
$message->from('xxxx', $employee->first_name . " " . $employee->last_name);
$message->replyTo($employee->email);
}
);
echo "send Email";
exit;
}
现在,当执行作业处理功能时,我遇到了获取电子邮件内容以发送电子邮件的问题。 这是获取电子邮件内容的代码
$payload = json_decode($event->job->getRawBody());
$data = unserialize($payload->data->command);
但是此代码不起作用。我的目标是使电子邮件内容使用该内容来发送电子邮件。
或者,如果您还有其他用于发送电子邮件的解决方案或选项。请也分享您的想法。
提前谢谢您。
答案 0 :(得分:0)
您可以在构建作业时传递您想要的任何数据,就像这样:
MySendEmailJob::dispatch('body', 'subject', 'email', $employee, 'clientname', 'docname', 'filename');
工作本身看起来像这样:
use Dispatchable,
InteractsWithQueue,
Queueable,
SerializesModels;
/**
* @var string
*/
private $body;
/**
* @var string
*/
private $subject;
/**
* @var string
*/
private $email;
/**
* @var User
*/
private $employee;
/**
* @var string
*/
private $clientName;
/**
* @var string
*/
private $docName;
/**
* @var string
*/
private $filename;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(
string $body,
string $subject,
string $email,
User $employee,
string $clientName,
string $docName,
string $filename
) {
$this->body = $body;
$this->subject = $subject;
$this->email = $email;
$this->employee = $employee;
$this->clientName = $clientName;
$this->docName = $docName;
$this->filename = $filename;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Mail::send(
['html' => 'emails.templates'],
['body' => $this->body, 'title' => $this->subject],
function ($message) {
$message->to($this->email, $this->clientName)->subject($this->subject);
$message->from('xxxx', $this->employee->first_name . " " . $this->employee->last_name);
$message->replyTo($this->employee->email);
}
);
}
查看Laravel docs以获得更多示例和文档