如何自定义Laravel Breeze发送的邮件样式及组件?
自定义Laravel Breeze邮件样式(以按钮为例)
1. 发布Laravel邮件组件文件
你之前只发布了notifications的模板,但x-mail::button这类组件属于Laravel核心邮件包的内容,需要单独发布:
php artisan vendor:publish --tag=laravel-mail
执行后会在resources/views/vendor/mail目录下生成完整的邮件组件,包括components/button.blade.php。
2. 修改按钮样式
打开resources/views/vendor/mail/components/button.blade.php,直接修改其中的内联样式即可。比如默认按钮的样式片段:
<a href="{{ $url }}" style="background-color: #2D3748; border: 1px solid #2D3748; border-radius: 3px; box-sizing: border-box; color: #FFFFFF; cursor: pointer; display: inline-block; font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol','Noto Color Emoji'; font-size: 14px; font-weight: 600; line-height: 1.5; padding: 8px 16px; text-decoration: none; text-transform: none; transition: background-color 0.2s ease; text-align: center;" target="_blank"> {{ $slot }} </a>
你可以调整background-color(背景色)、color(文字色)、border-radius(圆角)、padding(内边距)等属性,比如改成圆角蓝色按钮:
<a href="{{ $url }}" style="background-color: #3B82F6; border: 1px solid #3B82F6; border-radius: 6px; box-sizing: border-box; color: #FFFFFF; cursor: pointer; display: inline-block; font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol','Noto Color Emoji'; font-size: 14px; font-weight: 600; line-height: 1.5; padding: 10px 20px; text-decoration: none; text-transform: none; transition: background-color 0.2s ease; text-align: center;" target="_blank"> {{ $slot }} </a>
3. 生效范围
修改这个组件后,所有使用x-mail::button的邮件(包括Breeze的欢迎、验证、密码重置邮件)都会自动应用新样式,不用修改email.blade.php的内容,完全满足你“仅改样式不替换内容”的需求。
可选:仅针对Breeze邮件自定义样式
如果不想全局修改所有邮件按钮,只想调整Breeze相关邮件的样式,可以复制已发布的resources/views/vendor/notifications/email.blade.php到resources/views/notifications/email.blade.php(手动创建notifications目录),然后把文件里的<x-mail::button>替换成自定义的HTML按钮代码,这样只会影响Breeze发送的邮件。
内容的提问来源于stack exchange,提问作者pileup
相关产品推荐
相关产品推荐

