I want to send an email with Laravel, for that, no problem, the email is sent. However, the email I want to send includes two tables that I want to show to the user. Once the email is received, half of it is “illegible”. Only the first painting is interpreted, the second is shown in its raw form.
Here is my blade view.
<!-- resources/views/emails/visite/answer.blade.php -->
@component('mail::message')
@lang('Hello'),<br/><br/>
Votre demande de visite planifiée datant du {{ date('d/m/Y', strtotime($planif->created_at)) }} a été @if($planif->etat == 1) acceptée. @else refusée. @endif
@if($planif->etat == 1)
@component('mail::table')
| Nom | Prénom | Société |
|-----------|-----------|-------------|
@foreach(json_decode($planif->final_visiteurs) as $item)
| {{ $item->name }} | {{ $item->firstname }} | {{ $item->societe }} |
@endforeach
@endcomponent
<br/><br/>
@component('mail::table')
| Modèle | Immatriculation |
|---------------|------------------|
@foreach(json_decode($planif->final_vehicules) as $item)
| @if($item->modele != null) {{ $item->modele }} @else Non renseigné @endif | {{ $item->immat }} |
@endforeach
@endcomponent
@endif
Pour plus d'informations, veuillez contacter l'ASIP.
@lang('Sincerely yours')<br>
EamusCork
@endcomponent
Here is the function that sends the email.
public function accept_planif(Request $request, $id){
$planif = PlanificationVisite::findOrFail($id);
$vis_final = [];
if($request->input('vis')){
$vis = json_decode($request->input('vis')[0]);
for($i = 0; $i < count($vis); $i++){
$vis_final[] = [
'name' => $vis[$i]->name,
'firstname' => $vis[$i]->firstname,
'societe' => $vis[$i]->societe,
'document' => $vis[$i]->document
];
}
}
$veh_final = [];
if($request->input('veh')){
$veh = json_decode($request->input('veh')[0]);
for($i = 0; $i < count($veh); $i++){
$veh_final[] = [
'grise' => $veh[0]->grise,
'immat' => $veh[0]->immat,
'modele' => $veh[0]->modele,
];
}
}
$planif->update(['final_visiteurs' => json_encode($vis_final), 'final_vehicules' => json_encode($veh_final), 'etat' => 1]);
$email = new AnswerPlanificationVisite($planif);
Mail::to($planif->email_sent)->locale('fr')->send($email);
return redirect()->route('visite.see_planif');
}
This is how the email is rendered.
(I will show my image later when I have enough reputation. In the meantime here is the HTML rendering.)
Bonjour,
Votre demande de visite planifiée datant du 21/05/2024 a été acceptée.
Visiteurs concernés
Nom Prénom Société
Smee Cédric Eamus Cork
Ditacroute Thomas Eamus Cork
Ben Arfa Karim Eamus Cork
<br/><br/>
<p><strong>Véhicules concernés</strong></p>
<table class="table">
<thead>
<tr>
<th>Modèle</th>
<th>Immatriculation</th>
</tr>
</thead>
<tbody>
<tr>
<td> Ford Transit </td>
<td>AB-123-CD</td>
</tr>
<tr>
<td> Ford Transit </td>
<td>AB-123-CD</td>
</tr>
<tr>
<td> Ford Transit </td>
<td>AB-123-CD</td>
</tr>
</tbody>
</table>
Pour plus d'informations, veuillez contacter l'ASIP.
Cordialement
EamusCork
I tried to modify the blade view directly using the , , … tags without success. As you can see, the components don’t work any better. I checked the documentation for the use of “Mail”, I don’t think I made an error on the sending function and I use markdown correctly.