首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么html标签不呈现在拉拉发送电子邮件?

为什么html标签不呈现在拉拉发送电子邮件?
EN

Stack Overflow用户
提问于 2021-12-31 05:46:08
回答 1查看 664关注 0票数 0

用电子邮件

代码语言:javascript
复制
\Mail::to( 

方法在laravel 8应用程序中,我在im我的电子邮件模板中有html标记。

代码语言:javascript
复制
@component('mail::message')
    <h3 >
         You registered at {{ $site_mame }}
    </h3>


    Best regards, <br>
    ...
@endcomponent

以及我的app/Mail/UserRegistered.php中的代码:

代码语言:javascript
复制
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class UserRegistered extends Mailable
{
    use Queueable, SerializesModels;

    public $site_mame;
    public $user;
    public $confirmation_code;

    public function __construct( $site_mame, $user, $confirmation_code )
    {
        $this->site_mame = $site_mame;
        $this->user = $user;
        $this->confirmation_code = $confirmation_code;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('email.UserRegisteredEmail')
                    ->with('site_mame', $this->site_mame)
                    ->with('user', $this->user)
                    ->with('confirmation_code', $this->confirmation_code);
    }
}

在我的.env文件中使用sendgrid选项,我在google帐户上得到了有效的emaul,但是html标记没有呈现。如果有一种方法来呈现所有html标记?它是否依赖于laravel应用程序/电子邮件选项,或设置在我的谷歌(或其他一些帐户)。我能从我身边做些什么?

更新的:修改的

代码语言:javascript
复制
$this->view(

我有错误:

代码语言:javascript
复制
No hint path defined for [mail]. (View: project/resources/views/email/UserRegisteredEmail.blade.php) 

指向我的刀片文件。在网上搜索,我发现这是可能的决定:

代码语言:javascript
复制
php artisan vendor:publish --tag=laravel-mail

并清除所有缓存

但我还是犯了同样的错误。我错过了一些选择吗?

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2021-12-31 06:18:50

您正在使用markdown()方法,它是一种在邮件中利用预先构建的模板和邮件通知组件的方法。

这提供了许多优点:

  • ,而不是在h1、h2等标签中包装标题,您只需在行

的开头放置一个#、##等

  • 不需要在<ul>中包装列表,在<li>标记中列出项目。在标记中,您只需使用一个破折号(-)来列出元素

  • 斜体/粗体字体可以通过在要强调

的文本周围放置*/**来实现。

您可以在官方的Laravel文档中更多地了解到这一点。

https://laravel.com/docs/8.x/mail#markdown-mailables

如果您想使用HTML,可以只呈现一个视图:

代码语言:javascript
复制
    /**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->view('email.UserRegisteredEmail')
                ->with('site_mame', $this->site_mame)
                ->with('user', $this->user)
                ->with('confirmation_code', $this->confirmation_code);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70539369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档