为什么我的电子邮件无法解释我的代码并显示原始代码?

问题描述 投票:0回答:1

我想用 Laravel 发送一封电子邮件,为此,没问题,电子邮件已发送。但是,我要发送的电子邮件包含两个要向用户显示的表格。收到电子邮件后,其中一半是“难以辨认”的。仅解释第一个表,第二个表以其原始形式显示。

这是我的刀片视图。

<!-- 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

这是发送电子邮件的函数。

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');
    }

这就是电子邮件的呈现方式。 enter image description here

我尝试直接使用

<table>
<thead>
<tbody>
...标签修改刀片视图,但没有成功。正如您所看到的,这些组件并没有更好地工作。我检查了“\Mail”的使用文档,我认为我在发送功能上没有犯错误并且我正确使用了markdown。

这是电子邮件的源代码。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- resources/views/emails/visite/answer.blade.php -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="color-scheme" content="light">
<meta name="supported-color-schemes" content="light">
<style>
@media  only screen and (max-width: 600px) {
.inner-body {
width: 100% !important;
}

.footer {
width: 100% !important;
}
}

@media  only screen and (max-width: 500px) {
.button {
width: 100% !important;
}
}
</style>
</head>
<body style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; -webkit-text-size-adjust: none; background-color: #ffffff; color: #718096; height: 100%; line-height: 1.4; margin: 0; padding: 0; width: 100% !important;"><img width="1" height="1" src='https://eciaccf.r.af.d.sendibt2.com/tr/op/OMollFTSRvBkb0jY8o-Ta5M0ZXU2U9xek8HU1_4aS2kfcplPBady8fOFepn-GeSkXsf7hUonWZMug_rFnjHlQBu7NcwO_S_3A992F6GQmP1NeVR-G6ToB15anoIFSHE-_gBX-1rmRA3EIII1xqORV1l3ZQFVzehDUlJv_Z1IGwvr7kDrFCUoOFfziW8kw2QVNVens6HQdhnjuR0cD_vbGD7HTXp_' />

<table class="wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%; background-color: #edf2f7; margin: 0; padding: 0; width: 100%;">
<tr>
<td align="center" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative;">
<table class="content" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%; margin: 0; padding: 0; width: 100%;">
<tr>
<td class="header" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; padding: 25px 0; text-align: center;">
<a href="https://eciaccf.r.af.d.sendibt2.com/tr/cl/y4U0BaZi9-XI2z1JSr3N1odchSxYa4dWK4m8d9ekqrnzcfXJjkffCBTaq7vudG9jtBGlux8ZSQGnuEMI8ubBrSTJsxR4zuwTpfwrsGmBEY0RJd4zeSTiW2vkyFXUOYf-q5nVcX8cIBCgFDTM3D6IgrpDRXCcZxyXJAuDGhmc7MF0U6ZsvyDf58PtE9CBU1m6rNzqbTqhhmtuJarYLMWdbBA3VWL2C4cyqwn2AsnAYaI6BHRJV2AgDU1TIjlQ6talXhgQ0n8Xm7dqzR9kqQ" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #3d4852; font-size: 19px; font-weight: bold; text-decoration: none; display: inline-block;">
EamusCork - Alerte
</a><br>
<span class="text-sm" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; font-size: 10px;">Ne pas répondre à cet e-mail</span>
</td>
</tr>

<!-- Email Body -->
<tr>
<td class="body" width="100%" cellpadding="0" cellspacing="0" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%; background-color: #edf2f7; border-bottom: 1px solid #edf2f7; border-top: 1px solid #edf2f7; margin: 0; padding: 0; width: 100%;">
<table class="inner-body" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 570px; background-color: #ffffff; border-color: #e8e5ef; border-radius: 2px; border-width: 1px; box-shadow: 0 2px 0 rgba(0, 0, 150, 0.025), 2px 4px 0 rgba(0, 0, 150, 0.015); margin: 0 auto; padding: 0; width: 570px;">
<!-- Body content -->
<tr>
<td class="content-cell" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; max-width: 100vw; padding: 32px;">
<p style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;">Bonjour,<br><br></p>
<p style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;">Votre demande de visite planifiée datant du 21/05/2024 a été  acceptée.
</p>
<p style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;"><strong style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative;">Visiteurs concernés</strong></p>
<table class="table" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative;">
<thead style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative;">
<tr>
<th style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; border-bottom: 1px solid #edeff2; margin: 0; padding-bottom: 8px;">Nom</th>
<th style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; border-bottom: 1px solid #edeff2; margin: 0; padding-bottom: 8px;">Prénom</th>
<th style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; border-bottom: 1px solid #edeff2; margin: 0; padding-bottom: 8px;">Société</th>
</tr>
</thead>
<tbody style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative;">
<tr>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #74787e; font-size: 15px; line-height: 18px; margin: 0; padding: 10px 0;">Smee</td>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #74787e; font-size: 15px; line-height: 18px; margin: 0; padding: 10px 0;">Cédric</td>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #74787e; font-size: 15px; line-height: 18px; margin: 0; padding: 10px 0;">Eamus Cork</td>
</tr>
<tr>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #74787e; font-size: 15px; line-height: 18px; margin: 0; padding: 10px 0;">Ditacroute</td>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #74787e; font-size: 15px; line-height: 18px; margin: 0; padding: 10px 0;">Thomas</td>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #74787e; font-size: 15px; line-height: 18px; margin: 0; padding: 10px 0;">Eamus Cork</td>
</tr>
<tr>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #74787e; font-size: 15px; line-height: 18px; margin: 0; padding: 10px 0;">Ben Arfa</td>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #74787e; font-size: 15px; line-height: 18px; margin: 0; padding: 10px 0;">Karim</td>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; color: #74787e; font-size: 15px; line-height: 18px; margin: 0; padding: 10px 0;">Eamus Cork</td>
</tr>
</tbody>
</table>
<pre style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative;"><code>&lt;br/&gt;&lt;br/&gt;

&lt;p&gt;&lt;strong&gt;Véhicules concernés&lt;/strong&gt;&lt;/p&gt;
&lt;table class="table"&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Modèle&lt;/th&gt;
            &lt;th&gt;Immatriculation&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
                        &lt;tr&gt;
                &lt;td&gt; Ford Transit &lt;/td&gt;
                &lt;td&gt;AB-123-CD&lt;/td&gt;
            &lt;/tr&gt;
                        &lt;tr&gt;
                &lt;td&gt; Ford Transit &lt;/td&gt;
                &lt;td&gt;AB-123-CD&lt;/td&gt;
            &lt;/tr&gt;
                        &lt;tr&gt;
                &lt;td&gt; Ford Transit &lt;/td&gt;
                &lt;td&gt;AB-123-CD&lt;/td&gt;
            &lt;/tr&gt;
                &lt;/tbody&gt;
&lt;/table&gt;
</code></pre>
<p style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;">Pour plus d'informations, veuillez contacter l'ASIP.</p>
<p style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;">Cordialement<br>
EamusCork</p>



</td>
</tr>
</table>
</td>
</tr>

<tr>
<td style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative;">
<table class="footer" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 570px; margin: 0 auto; padding: 0; text-align: center; width: 570px;">
<tr>
<td class="content-cell" align="center" style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; max-width: 100vw; padding: 32px;">
<p style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative; line-height: 1.5em; margin-top: 0; color: #b0adc5; font-size: 12px; text-align: center;"><i style="box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; position: relative;">Article L612-14 du CSI : L'autorisation d'exercice ne confère aucune prérogative de puissance publique à l'entreprise ou aux personnes qui en bénéficient.</i><br>
© 2024 DEVS - Portail Agent. All rights reserved.</p>

</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
php html laravel laravel-blade
1个回答
1
投票

要修复此错误,检查空格和缩进非常重要。 Markdown 对这些元素非常敏感,如果两者之一未正确使用,则所有其余代码都不会被解释。

我对 Blade 不太了解,但我认为这将归结为以下内容: | @if($item->modele!= null)。 Markdown 对空格非常敏感。你能把 if 分成多行,然后有 | {{ $item->modele }} 相反,确保缩进与表格本身保持在同一水平?

@克里斯·哈斯

这是我更改前的代码:

<!-- 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

现在是我的代码:

<!-- 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
    <br/><br/>
@endif

Pour plus d'informations, veuillez contacter l'ASIP.

@lang('Sincerely yours')<br>
EamusCork
@endcomponent

您可以看到第二张桌子的情况略有变化。这个小错误足以导致这个原始代码显示错误。

© www.soinside.com 2019 - 2024. All rights reserved.