0
I am attaching a PDF to send in the email, using Laravel and DOMPDF but when the email arrives, there is no PDF attachment, it arrives encoded in the body of the email. follows the code.
Remembering that the PDF is generated 100%. I can see it through the browser. but send so in email
public function enviarEmail(Request $request, $id)
{
$orcamento = $this->orcamentosService->exibir($id);
$data["email"] = $request->get("email");
$data["client_name"] = $request->get($orcamento->cliente->nome);
$data["subject"] = $request->get("assunto");
$pdf = PDF::loadView('paginas.orcamentos.imprimir', ['orcamento' => $orcamento])->setPaper('a4', 'portrait');
try{
Mail::send('emails.orcamento', $data, function($message)use($data,$pdf) {
$message->to($data["email"], $data["client_name"])
->from('xxx')
->subject($data["subject"])
->attachData($pdf->output(), "orcamento.pdf", ['mime' => 'application/pdf']);
});
}catch(JWTException $exception){
$this->serverstatuscode = "0";
$this->serverstatusdes = $exception->getMessage();
}
if (Mail::failures()) {
$this->statusdesc = "Erro ao enviar e-mail";
$this->statuscode = "0";
}else{
$this->statusdesc = "Email enviado com sucesso";
$this->statuscode = "1";
}
return response()->json(compact('this'));
}
And here as the PDF arrives in the email
Actually the attachData() method does not need a file generated on the hard drive, it uses file generated in memory, which is what I am doing. https://laravel.com/docs/5.6/mail#attachments. I think the problem is different, it doesn’t seem to be rendering the PDF.
– MichaelCosta
Have then tried using a method that extens the
Illuminate\Mail\Mailable
to send instead of directly using the classMail
?– Erlon Charles
our brother.. after much suffering.. I discovered the problem.. if the body of the email is empty, it shoves the file into the body of the email, so it was not enough as an attachment. it was inserted into the body of the email..
– MichaelCosta