PHPackages                             bredabeds/magento-email-attachments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. bredabeds/magento-email-attachments

ActiveMagento2-module[Mail &amp; Notifications](/categories/mail)

bredabeds/magento-email-attachments
===================================

Magento 2 module for adding attachments to emails by BredaBeds

121PHP

Since Aug 12Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/BredaBeds/magento-email-attachments)[ Packagist](https://packagist.org/packages/bredabeds/magento-email-attachments)[ RSS](/packages/bredabeds-magento-email-attachments/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

magento-email-attachments
=========================

[](#magento-email-attachments)

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

Template Variables
------------------

[](#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
---------------------------------------------------

[](#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'
    ]
]

```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance41

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c2e093f736c0676f82fe0ebe33c41a1212491d1c7b6f246f1bcce80566b43882?d=identicon)[bredabeds](/maintainers/bredabeds)

---

Top Contributors

[![ootri](https://avatars.githubusercontent.com/u/3450878?v=4)](https://github.com/ootri "ootri (4 commits)")

### Embed Badge

![Health badge](/badges/bredabeds-magento-email-attachments/health.svg)

```
[![Health](https://phpackages.com/badges/bredabeds-magento-email-attachments/health.svg)](https://phpackages.com/packages/bredabeds-magento-email-attachments)
```

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
