【发布时间】:2020-05-18 05:37:04
【问题描述】:
我发现我附加到电子邮件的 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();
}
我的可邮寄:
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;
}
}
我的电子邮件标记:
@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 输出:
但在 RAW 部分:它显示附加了一个 pdf:
我已经在网上搜索并实施了几乎所有我找到的解决方案来尝试解决这个问题,但没有成功。我尝试过使用 public_path()、storage_path()、attachData() 等等!我只是不知道如何继续并完成这项工作。
【问题讨论】:
-
在邮件陷阱中单击
show info时会显示什么? -
感谢您的回复!这是我的无知,我不知道 Mailtrap 显示附件的方式与 Gmail、Yahoo 和 Yandex 等邮件服务提供商的显示方式不同——它一直出现在邮件右上角...
标签: php laravel email dompdf laravel-5.7