Saltar al contenido

¿Puedo pasar un archivo adjunto en el ejemplo de código de laravel del administrador de correo?

Ejemplo: enviar correo con archivo adjunto en el controlador laravel 8

Reference link
Laravel Emails | Sending emails with multiple attachments
# add Use Mail; use AppMailPurchaseInvoiceInformation; public function sendEmailWithMultipleAttachments(Request $request){ $data = [ "to" => "[email protected]", "attachments" => [ [ "path" => public_path('uploads/inv-005.pdf'), "as" => "Purchase Invoice NO 005.pdf", "mime" => "application/pdf", ], [ "path" => public_path('uploads/inv-007.pdf'), "as" => "Purchase Invoice NO 007.pdf", "mime" => "application/pdf", ], [ "path" => public_path('uploads/inv-009.pdf'), "as" => "Purchase Invoice NO 009.pdf", "mime" => "application/pdf", ], ], ]; return Mail::to($data['to'])->send(new PurchaseInvoiceInformation($data)); } # AppMailPurchaseInvoiceInformation; <?php namespace AppMail; use IlluminateBusQueueable; use IlluminateContractsQueueShouldQueue; use IlluminateMailMailable; use IlluminateQueueSerializesModels; class PurchaseInvoiceInformation extends Mailable { use Queueable, SerializesModels; /** * Create a new message instance. * * @return void */ protected $data; public function __construct($data) { $this->data = $data; } /** * Build the message. * * @return $this */ public function build() { $mail = $this->from('[email protected]') ->view('emails.purchase-invoice-information'); if(!empty($this->data["attachments"])){ foreach($this->data["attachments"] as $k => $v){ $mail = $mail->attach($v["path"], [ 'as' => $v["as"], 'mime' => $v["mime"], ]); } } } } # blade file <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Purchase Invoice</title> </head> <body> <h1>Invoice Information</h1> <p>Dear User,</p> <p>Find invoices for your purchase order INV005, INV007, INV009.</p> </body> </html>
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *