/
Email.php
56 lines (46 loc) · 1.49 KB
/
Email.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace App\Jobs;
use App\Model\EmailLog as EmailLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldBeQueued;
use Mail;
class Email extends Job implements SelfHandling, ShouldBeQueued
{
use InteractsWithQueue, SerializesModels;
private $log;
/**
* 邮件日志
*
*/
public function __construct($appId, $userId, $email, $subject, $content)
{
$this->log = array('app_id' => $appId,
'user_id' => $userId,
'email' => $email,
'subject' => $subject,
'content' => $content,
'pushed_at' => date("Y-m-d H:i:s")
);
}
/**
* Execute the command.
*
* @return void
*/
public function handle()
{
$popedAt = date('Y-m-d H:i:s');
echo '[', $popedAt, ']', '[Email Log]...';
// 发送邮件
$mail = $this->log;
$mail = Mail::send('emails.custom', $mail, function($message) use ($mail) {
$message->from(env('MAIL_USERNAME'), env('MAIL_FROMNAME'));
$message->to($mail['email'])->subject($mail['subject']);
});
// 记录日志
$user_log = EmailLogModel::create(array_merge($this->log, array('poped_at' => $popedAt, 'created_at' => date('Y-m-d H:i:s'))));
echo 'OK!';
}
}