Вложение PDF не отображается в выводе mailrap HTML, но отображается в разделе RAW - Laravel 5.7 - PullRequest
0 голосов
/ 02 февраля 2020

Я обнаружил, что файл PDF, который я прикрепил к своей электронной почте, не отображается при доставке на мою электронную почту в Mailtrap, но отображается в разделе данных RAW.

Мой метод контроллера для отправки электронной почты:

public function store(Request $request)
{
    $this->validate($request, [
      'name' => 'required',
      'email' => 'required|email',
      'quantity' => 'required|numeric|digits:1',
    ]);

    if ($request->quantity > 5) {
        toastr()->error('Only 5 tickets per booking is allowed');
        return redirect()->back();
    }

    $a = 0;
    $file = array();
    while ($a < $request->quantity) {

        $ordercode = substr(md5(time() . mt_rand(1, 1000000)), 0, 22);
        $qrcodepath = 'assets/payments/qrcodes/'.str_slug($request->name).time().'.png';
        $qrcode = QrCode::format('png')->size(400)->generate($ordercode, $qrcodepath);

        $data["name"] = $request->name;
        $data["email"] = $request->email;
        $data["qrcode"] = $qrcodepath;
        $data["ordercode"] = $ordercode;

        $pdf = PDF::loadView('pdf.payment', $data);
        $pdfpath = 'assets/payments/pdf/'.str_slug($request->name).time().'.pdf';
        $pdf->save($pdfpath);

        $payment = Payment::create([
          'fullname' => $request->name,
          'qrcode' => $qrcodepath,
          'ordercode' => $ordercode,
          'email' => $request->email,
          'quantity' => 1,
          'pdfticket' => $pdfpath
        ]);

        $file[] = $payment->pdfticket;
        $a++;
        sleep(1);
    }

    $data = array(
        'name' => $payment->fullname,
        'tickets' => $file,
    );

    Mail::to($payment->email)->send(new PurchaseComplete($data));

    dd($payment->email);

    toastr()->success('Payment created successfully');

    return redirect()->back();
}

My Mailable:

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class PurchaseComplete extends Mailable
{
    use Queueable, SerializesModels;

    public $data;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $message = $this->subject('Ticket Purchase - CodeRed')->markdown('emails.purchase.complete')->with('data', $this->data);

        $count = 0;
        foreach ($this->data['tickets'] as $ticket) {
            $count++;
            $message->attach(asset($ticket), array(
                'as' => 'ticket'.$count.'.pdf',
                'mime' => 'application/pdf',
            ));
        }

        return $message;
    }
}

My Email Markdown:

@component('mail::message')
# Hello {{ $data['name'] }}

Your Ticket Purchase: Please find attached files below.

Ensure you download the ticket and load it on your phone when you arrive!

You can also Login to your profile to download the Qrcode for a quick scan and copies of your tickets!

@component('mail::button', ['url' => route('login')])
Login
@endcomponent

If you have any further questions: contact us through the contact section on our website.

Thanks,<br>
{{ config('app.name') }}

@endcomponent

Mailtraps HTML вывод почты:

No PDF attached to the email

Но в разделе RAW: это показывает, что PDF-файл был прикреплен:

PDF shows that it was attached

Я искал Я реализовал практически все решения, которые я нашел, чтобы попытаться решить эту проблему, но безуспешно. Я пытался использовать public_path (), storage_path (), attachData () и многое другое! Я просто не знаю, как поступить и сделать эту работу.

1 Ответ

0 голосов
/ 02 февраля 2020

Мне плохо за это: я не знал, что Mailtrap отображает вложения в отличие от других поставщиков почтовых услуг ...

enter image description here

...