Я пытаюсь генерировать QR-коды на лету при отправке электронных писем с помощью Gmail smtp и laravel 11. Сначала qr-код не генерировался, он всегда был пустым, затем я попробовал рекомендацию здесь. Мой qr-код все еще не виден. Любые советы или рекомендации о том, что я могу прочитать, чтобы получить правильный формат сканируемого кода, будут оценены по достоинству. В настоящее время он создается как часть вложения.
Вот мой класс:
class ConfirmAttendance extends Mailable
{
use Queueable, SerializesModels;
private $name;
private $id;
public function __construct($name, $id)
{
$this->name = $name;
$this->id = $id;
}
public function envelope(): Envelope
{
return new Envelope(
subject: 'Ticket Information!',
);
}
public function content(): Content
{
$qrCodeAsPng = QrCode::format('png')->size(500)->generate($this->id);
$qrCodeBase64 = base64_encode($qrCodeAsPng);
return new Content(
view: 'mail.confirm-attendance',
with: [
'name' => $this->name,
'id' => $this->id,
'qrCodeBase64' => $qrCodeBase64,
],
);
}
public function attachments(): array
{
$qrCodeAsPng = QrCode::format('png')->size(500)->generate($this->id);
$attachmentName = 'qr_code.png';
return [
\Illuminate\Mail\Mailables\Attachment::fromData(
fn() => $qrCodeAsPng,
$attachmentName,
'image/png'
),
];
}
}
Вот мой шаблон клинка:
Dear {{ $name }},
Congratulations! We're thrilled to have you join us for this exciting event!
Your Ticket QR Code:
[img]data:image/png;base64,{{ $qrCodeBase64 }}[/img]
Ticket ID: {{ $id }}
Подробнее здесь: https://stackoverflow.com/questions/790 ... sent-email