PHPackages                             skylarkltd/laravel-freesend - 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. skylarkltd/laravel-freesend

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

skylarkltd/laravel-freesend
===========================

Laravel mail driver for the Freesend email API

v1.0.1(5mo ago)10MITPHPPHP ^8.1CI passing

Since Jan 21Pushed 5mo agoCompare

[ Source](https://github.com/skylark-ltd/laravel-freesend)[ Packagist](https://packagist.org/packages/skylarkltd/laravel-freesend)[ RSS](/packages/skylarkltd-laravel-freesend/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

Laravel Freesend
================

[](#laravel-freesend)

A Laravel mail driver for the [Freesend](https://freesend.metafog.io) email API.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require skylarkltd/laravel-freesend
```

Configuration
-------------

[](#configuration)

Add a Freesend API key to your `.env` file:

```
FREESEND_API_KEY=your-api-key-here
```

Add the Freesend mailer to your `config/mail.php` mailers array:

```
'mailers' => [
    // ... other mailers

    'freesend' => [
        'transport' => 'freesend',
    ],
],
```

To use Freesend as your default mailer, set it in your `.env`:

```
MAIL_MAILER=freesend
```

### Custom Endpoint

[](#custom-endpoint)

If you need to use a different API endpoint (e.g., a self-hosted instance), you can configure it via environment variable:

```
FREESEND_ENDPOINT=https://your-custom-endpoint.com/api/send-email
```

### Sender Configuration

[](#sender-configuration)

Configure the default sender address and name in your `.env` file:

```
MAIL_FROM_ADDRESS=noreply@example.com
MAIL_FROM_NAME="My Application"
```

These values are set in Laravel's `config/mail.php`:

```
'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],
```

You can also set the sender per-email in your Mailable classes using the `envelope()` method.

Usage
-----

[](#usage)

Once configured, you can use Laravel's standard mail functionality:

### Using Mailables

[](#using-mailables)

```
use App\Mail\WelcomeEmail;
use Illuminate\Support\Facades\Mail;

Mail::to('recipient@example.com')->send(new WelcomeEmail());
```

### Using the Mail Facade Directly

[](#using-the-mail-facade-directly)

```
use Illuminate\Support\Facades\Mail;

Mail::raw('Hello, this is a test email!', function ($message) {
    $message->to('recipient@example.com')
            ->subject('Test Email');
});
```

### With Attachments

[](#with-attachments)

Standard Laravel attachments are fully supported:

```
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;

// In your Mailable class:
public function content(): Content
{
    return new Content(
        view: 'emails.invoice',
    );
}

public function attachments(): array
{
    return [
        Attachment::fromPath('/path/to/invoice.pdf'),
        Attachment::fromStorage('reports/monthly.pdf'),
        Attachment::fromData(fn () => $this->pdf, 'invoice.pdf')
            ->withMime('application/pdf'),
    ];
}
```

### URL-Based Attachments

[](#url-based-attachments)

The Freesend API supports fetching attachments directly from URLs, which can be more efficient for large files or files already hosted online. Use the `UrlAttachment` helper:

```
use Illuminate\Mail\Mailables\Attachment;
use Skylarkltd\Freesend\UrlAttachment;

public function attachments(): array
{
    return [
        // Standard file attachment
        Attachment::fromPath('/path/to/local-file.pdf'),

        // URL-based attachment - Freesend fetches the file from the URL
        UrlAttachment::fromUrl(
            'https://example.com/files/report.pdf',
            'monthly-report.pdf',
            'application/pdf'  // Optional content type
        ),

        // Works great with cloud storage temporary URLs
        UrlAttachment::fromUrl(
            Storage::temporaryUrl('documents/contract.pdf', now()->addMinutes(30)),
            'contract.pdf',
            'application/pdf'
        ),
    ];
}
```

**URL Attachment Limitations:**

- Only HTTP/HTTPS URLs are supported
- Maximum file size: 25MB
- Freesend has a 30-second timeout for fetching URL-based attachments

### Specifying Freesend for a Specific Email

[](#specifying-freesend-for-a-specific-email)

```
Mail::mailer('freesend')
    ->to('recipient@example.com')
    ->send(new WelcomeEmail());
```

Full Example
------------

[](#full-example)

Here's a complete example of a Mailable class using Freesend with all features:

```
