bredabeds/magento-email-attachments 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bredabeds/magento-email-attachments

Composer 安装命令:

composer require bredabeds/magento-email-attachments

包简介

Magento 2 module for adding attachments to emails by BredaBeds

README 文档

README

This module adds the ability to programatically send attachments with Magento 2 emails.

Template Variables

Method 1 (template variables):

->setTemplateVars([
    'attachments' => '/path/to/document.pdf'
])

Method 2 (template variables):

// 'type' and 'filename' are optional
// If 'type' is not set, mime_content_type is used to guess
// If 'filename' is not set, the filename from the path is used
->setTemplateVars([
    'attachments' => [
        'path' => '/path/to/document.xlsx',
        'type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'filename' => 'Document.xlsx'
    ]
])

Method 3 (template variables):

->setTemplateVars([
    'attachments' => [
        '/path/to/document1.pdf',
        [
            'path' => '/path/to/document2.xlsx',
            'type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // optional
            'filename' => 'document2.xlsx' // optional
        ],
        '/path/to/document3.docx'
    ]
])

Method 4 (addAttachment function):

$absolutePath = '/path/to/document1.pdf';
$transport = $this->transportBuilder
    ->setTemplateIdentifier('simple_text_email')
    ->setTemplateOptions([
        'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
        'store' => $this->storeManager->getStore()->getId()
    ])
    ->setTemplateVars([
        'email_subject' => $subject,
        'message' => $body,
        'attachments' => $absolutePath // Can be added here via template variables
    ])
    ->setFromByScope($this->contactsConfig->emailSender())
    ->addTo($to)
    ->addAttachment(file_get_contents($absolutePath), basename($absolutePath), 'application/pdf'); // Or here

$transport->getTransport()->sendMessage();

Browserless PDF generation and basic email template

This module also has the ability to generate a PDF via Browserless from a URL and it has a very basic template called "simple_text_email" that allows the body and subject to be set via template variables (see above example). This module has a wrapper helper for that template:

public function __construct(
    protected \BredaBeds\EmailAttachments\Helper\SendBasicEmail $sendBasicEmail,
    protected \BredaBeds\EmailAttachments\Helper\Browserless $browserless
) { }

protected function sendTestEmail()
{
    $absolutePath = $this->browserless->generatePdfFromUrl(
        'https://google.com',   // URL 
        'google.pdf',           // Filename to use
        'pdf/files'             // Location in the "var" path
    ); // Saves a PDF to: "/path/to/magento/var/pdf/files/google.pdf"

    $this->sendBasicEmail->sendEmail(
        'test@example.com',     // To
        'Your PDF Document',    // Subject
        'Your PDF document is attached. Please contact us if you have any questions or concerns.',  // Body
        [$absolutePath] // Optional: Sets attachments via template variables, see methods 1-3 above.
    ); // Sends an email with the previously saved PDF
}

For Browserless to work, add to the ./app/etc/env.php file:

'bredabeds' => [
    'browserless' => [
        'endpoint' => '127.0.0.1:3000',
        'token' => 'secret-token'
    ]
]

bredabeds/magento-email-attachments 适用场景与选型建议

bredabeds/magento-email-attachments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bredabeds/magento-email-attachments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bredabeds/magento-email-attachments 我们能提供哪些服务?
定制开发 / 二次开发

基于 bredabeds/magento-email-attachments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2025-04-09