rsvpify/laravel-mail-auto-embed
Composer 安装命令:
composer require rsvpify/laravel-mail-auto-embed
包简介
Library for embed images in emails automatically
README 文档
README
Laravel Mail Auto Embed
Install
You can install the package via composer:
$ composer require rsvpify/laravel-mail-auto-embed
This package uses Laravel 5.5 Package Auto-Discovery.
For previous versions of Laravel, you need to add the following Service Provider:
$providers = [ ... \Rsvpify\LaravelMailAutoEmbed\ServiceProvider::class, ... ];
Usage
Its use is very simple, you write your markdown normally:
@component('mail::message')
# Order Shipped
Your order has been shipped!
@component('mail::button', ['url' => $url])
View Order
@endcomponent
Purchased product:

Thanks,<br>
{{ config('app.name') }}
@endcomponent
When sending, it will replace the link that would normally be generated:
<img src="https://domain.com/products/product-1.png">
by an embedded inline attachment of the image:
<img src="cid:3991f143cf1a86257f8671883736613c@Swift.generated">.
It also works for raw html too:
// eg: resources/vendor/mail/html/header.blade.php <tr> <td class="header"> <a href="{{ $url }}"> <img src="https://domain.com/logo.png" class="img-header"> </a> </td> </tr>
If you do not want to use automatic embedding for specific images (because they are hosted elsewhere, if you want to use some kind of image tracker, etc.)
simply add the attribute data-skip-embed in the image tag:
<img src="https://domain.com/logo.png" data-skip-embed class="img-header">
Local resources
For local resources that are not available publicly, use file:// urls, example
<img src="file://{{ resource_path('assets/img/logo.png') }}" alt="Logo" border="0"/>
Configuration
The defaults are set in config/mail-auto-embed.php. You can copy this file to your own config directory to modify the values using this command:
php artisan vendor:publish --provider="Rsvpify\LaravelMailAutoEmbed\ServiceProvider"
Explicit embedding configuration
By default, images are embedded automatically, unless you add the data-skip-embed attribute.
You can also disable auto-embedding globally by setting the MAIL_AUTO_EMBED environment variable to false.
You can then enable embedding for specific images with the data-auto-embed attribute.
# .env
MAIL_AUTO_EMBED=false
<p> <!-- Won't be embedded --> <img src="https://domain.com/logo.png" class="img-header"> </p> <p> <!-- Explicit embedding --> <img src="https://domain.com/item.png" data-auto-embed> </p>
Base64 embedding
If you prefer to use Base64 instead of inline attachments, you can do so by setting the MAIL_AUTO_EMBED_METHOD environment variable to base64.
Note that it will increase the e-mail size, and that it won't be decoded by some e-mail clients such as Gmail.
Mixed embedding methods
If you want to use both inline attachment and Base64 depending on the image, you can specify the embedding method as the data-auto-embed attribute value:
<p> <img src="https://domain.com/logo.png" data-auto-embed="base64"> </p> <p> <img src="https://domain.com/item.png" data-auto-embed="attachment"> </p>
Embedding entities
You might want to embed images that don't actually exist in your filesystem (stored in the database).
In that case, make the entities you want to embed implement the EmbeddableEntity interface:
namespace App\Models; use Rsvpify\LaravelMailAutoEmbed\Models\EmbeddableEntity; use Illuminate\Database\Eloquent\Model; class Picture extends Model implements EmbeddableEntity { /** * @param mixed $id * @return Picture */ public static function findEmbeddable($id) { return static::find($id); } /** * @return mixed */ public function getRawContent() { return $this->data; } /** * @return string */ public function getFileName() { return 'profile_'.$this->id.'.png'; } /** * @return string */ public function getMimeType() { return 'image/png'; } }
Then, you can use the embed:ClassName:id syntax in your e-mail template:
<p> <img src="embed:App\Models\Picture:123"> </p>
Contributing
Please feel free to submit pull requests if you can improve or add any features.
We are currently using PSR-2. This is easy to implement and check with the PHP Coding Standards Fixer.
rsvpify/laravel-mail-auto-embed 适用场景与选型建议
rsvpify/laravel-mail-auto-embed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.11k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel-mail-auto-embed」 「rsvpify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rsvpify/laravel-mail-auto-embed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rsvpify/laravel-mail-auto-embed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rsvpify/laravel-mail-auto-embed 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library for embed images in emails automatically
Library for embed images in emails automatically
Library for embed images in emails automatically
Library for embed images in emails automatically
统计信息
- 总下载量: 12.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-16