为什么我的Laravel应用有附件时不发送邮件?

时间:2018-10-16 18:06:58

标签: php laravel laravel-mail

我正在尝试发送带有附件的电子邮件,但该电子邮件已超时。我决定设置一个队列,因为无论如何我都需要,但是现在它只是在不发送的情况下进行处理。

$ php artisan queue:work
[2018-10-16 13:42:21][1] Processing: App\Jobs\MailQueue
[2018-10-16 13:42:22][1] Processed:  App\Jobs\MailQueue
[2018-10-16 13:42:22][2] Processing: App\Mail\NotificationMail
[2018-10-16 13:42:55][3] Processing: App\Mail\NotificationMail
[2018-10-16 13:43:57][4] Processing: App\Mail\NotificationMail
[2018-10-16 13:44:59][5] Processing: App\Mail\NotificationMail
[2018-10-16 13:46:01][6] Processing: App\Mail\NotificationMail
[2018-10-16 13:47:04][7] Processing: App\Mail\NotificationMail
[2018-10-16 13:48:06][8] Processing: App\Mail\NotificationMail
[2018-10-16 13:49:09][9] Processing: App\Mail\NotificationMail
[2018-10-16 13:50:15][10] Processing: App\Mail\NotificationMail
[2018-10-16 13:51:19][11] Processing: App\Mail\NotificationMail
[2018-10-16 13:52:22][12] Processing: App\Mail\NotificationMail
[2018-10-16 13:53:24][13] Processing: App\Mail\NotificationMail
[2018-10-16 13:54:26][14] Processing: App\Mail\NotificationMail
[2018-10-16 13:55:29][15] Processing: App\Mail\NotificationMail
[2018-10-16 13:56:34][16] Processing: App\Mail\NotificationMail
[2018-10-16 13:57:36][17] Processing: App\Mail\NotificationMail

我正在使用邮件陷阱:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=*****************
MAIL_PASSWORD=*****************
MAIL_ENCRYPTION=null

我的队列驱动程序设置为数据库:

'database' => [
    'driver' => 'database',
    'table' => 'jobs',
    'queue' => 'default',
    'retry_after' => 90,
],

这是我的工作班级:

<?php

namespace App\Jobs;

use App\Mail\NotificationMail;
use App\Models\Event;
use App\Models\Notification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;

class MailQueue implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $event;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Event $event)
    {
        $this->event = $event;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Mail::to($this->event->siteContacts[0]->email)->queue(
            new NotificationMail(Notification::where('slug', 'event-flyer')->first(), $this->event)
        );
    }
}

在添加附件后,我将尝试发送邮件:

public function build()
{
    $this->notification->body = $this->parse(
        merge_tags($this->notification->body), $this->notification->body
    );

    $path = null;

    if ($this->notification->slug == 'event-flyer') {
        $path = "events/{$this->event->agency->id}/{$this->event->id}/flyer.pdf";
        $pdf = PDF::loadView('event.print', ['event' => $this->event]);
        Storage::put($path, $pdf->output());
    }

    return $this->view('email.notification')
                ->attach($path)
                ->subject("MSU Notification: {$this->event->group_name_location}")
                ->with(['event' => $this->event, 'notification' => $this->notification]);
}

我正在使用xampp设置和default_socket_timeout=60。我还应该提到,如果删除attach调用,它将正常发送邮件。

0 个答案:

没有答案