mercredi 26 février 2020

Laravel-generated email not formatting HTML correctly

I am struggling with email formatting issue, with Laravel. I get the email content (HTML) from the database, which doesn't really matter, but then quotes get added around, the format is wrong and my email looks like this:

t formatting my email corres

Here is my code, thanks a lot for your help!

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cookie;

class InsuranceEmail extends Mailable
{
    use Queueable, SerializesModels;
    protected $attacheddoc;

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

    /**
     * Build the message.rubr
     *
     * @return $this
     */
    public function build()
    {
        $name = Auth::user()->nom . " " .  Auth::user()->prenom;

        $sqlContent="SELECT texte from blabla";

        $content = DB::connection('blabla')->select( DB::connection('blabla')->raw($sqlContent))[0]->texte;
        $content = str_replace('#memberName#', $name, $content);
        $content = str_replace('"', '', $content); //I tried this, without any hope ;)

        return $this->from('contact@blabla.net')
                ->markdown('emails.blabla')->with([
                    'title' => "Email onject",
                    'memberName' => $name,
                    'content' => $content,
                ])
                ->attach($this->attacheddoc, array(
                    'as' => 'attacheddoc.pdf', 
                    'mime' => 'application/pdf'));
    }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire