代码之家  ›  专栏  ›  技术社区  ›  John Halsey

在Laravel通知电子邮件中添加粗体文本和换行符

  •  -1
  • John Halsey  · 技术社区  · 8 年前

    line($text) 方法带来。所以我在通知类中尝试了这个。我也试过使用 \n

    return (new MailMessage)
    ->subject('Booking Confirmed - Please Read')
    ->greeting('Hello ' . $this->booking->user->first_name . ',')
    ->line('Thank you for booking. Here are your booking details:')
    ->line($this->booking->provider->providerType->name . '<br>' .
        $date . '<br>' .
        $this->booking->start_at . '<br>' .
        $this->booking->address_1 . '<br>' .
        $this->booking->address_2 . '<br>' .
        $this->booking->address_3 . '<br>' .
        $this->booking->city . '<br>' .
        $this->booking->postcode . '<br>' .
        '£' . $this->booking->price
    )
    ->line('<strong>Need to cancel?</strong><br>' .
        'Don\'t forget to contact the provider on the details above if you need to cancel or reschedule. 
        They won\'t mind, as long as you tell them.'
    )
    ->line('<strong>Payment</strong><br>' .
        'Pay the Service provider direct as you normally would. This keeps things simple and costs down.'
    )
    ->line('<strong>FAQ\'s</strong><br>' .
        'Please click here for more information'
    )
    ->line('<strong>Don\'t forget to leave feedback after!</strong><br>' .
        'Help build your relationship with your Service Providers by leaving feedback'
    )
    ->line('We hope to see you again soon!')
    

    我尝试过通过 php artisan vendor:publish --tag=laravel-mail 命令,然后更新 {{$line}} {!! $line !!}} 毫无喜悦。我想不通。

    像这样放在邮件夹里 enter image description here

    3 回复  |  直到 8 年前
        1
  •  10
  •   Nazmus Shakib    6 年前

    也许你已经完成了你的工作,因为这个问题太老了。但是我想和大家分享一个简单的方法,在Laravel邮件模板上编写HTML标记。

    首先,您需要导入 use Illuminate\Support\HtmlString;

    ->line(new HtmlString('Last date: <strong>' . $this->due_date . '</strong>'))
    

    HtmlString 类使您能够在邮件体上编写HTML标记。 这将有助于寻找这种解决方案的人。

    谢谢。

        2
  •  3
  •   John Halsey    8 年前

    我想出来了,万一有人跟我一样笨。
    我认为有两个原因导致这个坏掉。@DouwedeHaan建议我使用双引号而不是单引号 \n 虽然没什么效果,但和下一部分结合在一起,我觉得很有效果。

    呈现html的blade模板处于markdown状态。我还没弄明白。它的布局是具体的,我不小心打破了它后,我发表了它删除了一些行和格式的文件缩进打破了一切。

    我删除了文件,重新发布了模板,更新了所有的实例 {{$line}} {!! $line !!} 确保文件的其余部分保持原样,更新了我的通知以使用双引号并使用 <br/> <strong></strong> 标签,现在它的工作如预期。

    enter image description here

        3
  •  1
  •   Douwe de Haan    8 年前

    'This will create a
    new line'
    

    或使用 \n 带双引号

    "This will also create a \n new line"
    

    More info here

        4
  •  -4
  •   Khaled Al-Haj Salem    8 年前

    您确实需要更新notifications视图,这样您就走上了正确的轨道。

    $php工匠供应商:publish--tag=laravel通知

    这只是告诉刀锋不要逃避标签。

    希望这有帮助!

    推荐文章