Joh*_*sey 1 html php notifications laravel
Laravel 5.6
我正在尝试通过电子邮件发送 Laravel 通知。我想让一些文本加粗,并插入换行符,而不是该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!')
Run Code Online (Sandbox Code Playgroud)
我已经尝试过通过php artisan vendor:publish --tag=laravel-mail命令发布或不发布刀片模板,然后毫无乐趣地更新{{$line}}到{!! $line !!}}。想不通
Naz*_*kib 15
也许你已经完成了你的工作,因为这个问题太老了。但我想分享一种在 Laravel 邮件模板上编写 HTML 标签的简单方法。
首先,您需要导入
use Illuminate\Support\HtmlString;
->line(new HtmlString('Last date: <strong>' . $this->due_date . '</strong>'))
Run Code Online (Sandbox Code Playgroud)
本HtmlString类让你来写HTML标签的邮件正文。这对正在寻找此类解决方案的人会有所帮助。
谢谢。
我想出了这一点,以防其他人和我一样愚蠢。
我认为这个问题被打破有两个原因。@DouwedeHaan 建议我在使用时使用双引号而不是单引号,\n这没有多大作用,但与下一部分结合我认为可以解决问题。
渲染 html 的刀片模板是 markdown 格式的。我还没弄清楚这一点。它的布局是特定的,我在发布它后不小心破坏了它,删除了一些行并使用缩进格式化文件,这破坏了所有内容。
我删除了该文件,重新发布了模板,更新了所有实例,{{$line}}以{!! $line !!}确保文件的其余部分保持原样,更新了我的通知以使用双引号并坚持使用<br/>和<strong></strong>标签,现在它按预期工作。