Lightweight setup & reliable delivery

Send email in Slim

Add email sending to your Slim Framework app in minutes with Sidemail's official PHP SDK and developer‑friendly API. Sidemail takes care of deliverability, SPF/DKIM/DMARC, email layout, and infrastructure so your Slim routes can send reliable, production‑ready emails with minimal code.

Get startedRead API docs
Send a welcome email from a route
use Sidemail\Sidemail;

$app->post('/register', function (Request $request, Response $response) {
    $data = $request->getParsedBody();

    $sidemail = $this->get(Sidemail::class);

    $sidemail->sendEmail([
        'toAddress'     => $data['email'],
        'fromAddress'   => '[email protected]',
        'fromName'      => 'Your App',
        'templateName'  => 'Welcome',
        'templateProps' => ['firstName' => $data['name']],
    ]);

    $response->getBody()->write('User registered');
    return $response;
});

Quickstart: Send email in Slim

Start sending emails from your Slim app in three steps:

1

Install the Sidemail PHP SDK

Add Sidemail to your Slim project via Composer:

composer require sidemail/sidemail
2

Configure the DI container

Register the Sidemail client in your DI container (e.g. PHP-DI). The SDK reads SIDEMAIL_API_KEY from your environment automatically.

// app/dependencies.php
use Sidemail\Sidemail;
use Psr\Container\ContainerInterface;

return function (ContainerInterface $container) {
    $container->set(Sidemail::class, function () {
        return new Sidemail();
    });
};
3

Send email from a route

Retrieve the Sidemail instance from the container and call sendEmail. Pass the recipient, sender, and template or content. That's it.

$app->post('/register', function (Request $request, Response $response) {
    $data = $request->getParsedBody();
    $sidemail = $this->get(Sidemail::class);

    $sidemail->sendEmail([
        'toAddress'     => $data['email'],
        'fromAddress'   => '[email protected]',
        'fromName'      => 'Your App',
        'templateName'  => 'Welcome',
        'templateProps' => ['firstName' => $data['name']],
    ]);

    $response->getBody()->write('User registered');
    return $response;
});

Key features & perks

Why Sidemail for Slim Framework emails

  • Fast Slim email integration

    Send emails from your Slim routes in minutes. Sidemail's JSON API and official PHP SDK integrate naturally with Slim's lightweight architecture, with clear docs and copy‑paste examples that get you running in under 30 minutes.
  • Reliable email delivery

    Sidemail's rock‑solid infrastructure and careful sender vetting process ensure your emails consistently reach inboxes, not spam folders. It's a reliable choice for developers who need dependable email delivery without the complexity.
  • Custom sending domain with DKIM & SPF

    Send from your own domain and skip the tedious DNS configuration. Sidemail automatically sets up DKIM and SPF for you, two of the most critical factors for strong inbox delivery and sender reputation.
  • All‑in‑one email platform

    Sidemail covers everything you need in a single platform – transactional and marketing emails, email automation, subscriber collection, and contact management. A complete email solution that handles every use case in one place.
  • Premade email templates & no‑code editor

    Sidemail comes with a library of ready‑to‑use, battle‑tested email templates that look great across every inbox. Need something custom? The no‑code email editor makes it easy to build responsive templates from scratch, without writing any HTML.
  • Best‑in‑class developer experience

    Sidemail's email API is built with busy developers in mind — clear documentation, copy‑paste code examples in multiple languages, and thoughtful features that make integration and day‑to‑day use genuinely easier. From markdown email support and detailed logs to an MCP server and rich API data, Sidemail is the email platform developers love using.

Slim transactional email examples

With Sidemail, you can send any transactional email from Slim. Here are a few examples with code:

// Slim: Send an account verification email
$app->post('/register', function (Request $request, Response $response) {
    $data = $request->getParsedBody();
    $sidemail = $this->get(Sidemail::class);

    $sidemail->sendEmail([
        'toAddress'     => $data['email'],
        'fromAddress'   => '[email protected]',
        'fromName'      => 'Your App',
        'templateName'  => 'Email Verification',
        'templateProps' => [
            'verifyUrl' => 'https://yourapp.com/verify?token=' . $token,
        ],
    ]);

    $response->getBody()->write('User registered');
    return $response;
});

Verification email

Send a sign-up verification email with a one-time link or code to confirm the user's address.

  • It's best practice to include a clear call-to-action (button or link) in verification emails and to ensure the verification link expires for security.
  • Sidemail provides a ready-made account activation template to handle this use case.
See account activation email template
// Slim: Send a payment receipt email
$sidemail->sendEmail([
    'toAddress'     => $user['email'],
    'fromAddress'   => '[email protected]',
    'fromName'      => 'Your App',
    'templateName'  => 'Payment Receipt',
    'templateProps' => [
        'userName' => $user['name'],
        'amount'   => '$19.99',
        'date'     => date('M j, Y'),
    ],
]);

Receipt or notification email

Send a receipt, invoice, or generic notification to your user.

  • For receipts or order confirmations, include key details (amount, date, items) in the email.
  • Sidemail offers receipt and invoice email templates, and you can pass dynamic data via templateProps to populate the template.
See receipt email template
// Slim: Schedule a welcome email for 1 hour from now
$sidemail->sendEmail([
    'toAddress'     => '[email protected]',
    'fromAddress'   => '[email protected]',
    'fromName'      => 'Your App',
    'templateName'  => 'Welcome',
    'templateProps' => ['firstName' => 'Alex'],
    'scheduledAt'   => (new DateTime('+1 hour'))->format(DateTime::ATOM),
]);

Welcome email with scheduled delivery

Schedule a welcome email to be sent later, for example one hour after sign-up.

  • Use the scheduledAt field with an ISO timestamp to control exactly when the email is sent.
  • This is useful for onboarding flows where you want to delay the first message until the user has had a bit of time in your app.
See welcome email template
// Slim: Send a password reset email with Markdown
$markdown = file_get_contents(
    __DIR__ . '/../templates/emails/password-reset.md'
);

$sidemail->sendEmail([
    'toAddress'     => '[email protected]',
    'markdown'      => $markdown,
    'templateProps' => [
        'firstName' => 'Alex',
        'resetLink' => 'https://yourapp.com/reset?token=abc123xyz',
        'expiresIn' => '30 minutes',
    ],
]);
---
subject: "Reset your password"
fromAddress: "[email protected]"
fromName: "Your App Security"
---

Hi {firstName}, we received a request to reset your password.

[$btn Reset password]({resetLink})

This link expires in {expiresIn}.

Password reset email sent with Markdown

Sidemail's API gives you an option to write email content in Markdown, which is automatically transformed into pixel‑perfect, responsive emails that look great in every inbox and on every device. Each email is branded with your logo and styled to match your project's email design.

  • Store your password reset email in a .md file
  • Subject and sender are defined in the markdown frontmatter.
  • Pass dynamic values via templateProps(such as resetLink and expiresIn), which map directly to variables in your markdown.

Deliverability best practices

SPF, DKIM, and DMARC for transactional email

SPF and DKIM are authentication protocols that verify your emails are legitimately sent from your domain. And DMARC builds on both by instructing mail servers how to handle messages that fail those checks. Together, they are 3 critical factors for inbox delivery and sender reputation.

Sidemail automatically handles SPF, DKIM, and DMARC setup for you, so your Slim app sends authenticated, best‑practice‑compliant emails from day one.

Sidemail dashboard – Reliable email delivery
Graphics
Sidemail dashboard – No-code email editor
Graphics

The simplest way to build emails

No‑code email editor & premade email templates

Sidemail's no‑code email editor is the easiest way to create responsive email templates that render correctly across every client and device. No HTML knowledge required. Add your logo and brand colors, and you're ready to send.

Need to move even faster? Sidemail has a library of production‑ready templates for the most common use cases – password resets, welcome emails, receipts, and more. Whether you're building from scratch or customizing a premade template, we guarantee your emails look great everywhere.

Learn more

Developer‑friendly formatting

Markdown support for Slim emails

Writing and maintaining HTML emails by hand is tedious, especially when you just want to send clean, readable content.

Sidemail lets you write your email body in Markdown and automatically converts it into a responsive, well‑styled HTML email. You get smart formatting, like headings, lists, links, and code blocks, without worrying about broken layouts or cross‑client rendering issues.

Ideal for transactional emails generated from your Slim app – clean content, fast authoring, and zero HTML to debug.

Learn more
Markdown email code example and rendered preview

Get started today

Ready to send transactional emails from your Slim app? With Sidemail's API and premade templates, you can integrate in minutes and deliver emails reliably.

Start free trial

FAQs

How do I send email in Slim Framework?

The easiest way to send email from a Slim app is by using an email API like Sidemail. Install the PHP SDK (composer require sidemail/sidemail), register the client in your DI container, and call $sidemail->sendEmail() inside any route handler. No SMTP setup or complex configuration needed. Sidemail handles authentication, formatting, and deliverability for you.

Does Sidemail work with Slim's PSR-7 and DI container?

Yes. Sidemail's PHP SDK is a plain PHP class that works with any PSR-compliant setup. Register it in your DI container (like PHP-DI) and resolve it in route handlers with $this->get(Sidemail::class). It fits naturally into Slim's lightweight, standards-based architecture.

How do I use email templates with Slim?

Instead of building email HTML in your routes, use Sidemail's template system. In the Sidemail dashboard, pick a premade template or create your own with the drag‑and‑drop editor. Then in your Slim route, reference the template by templateName and pass personalization data via templateProps. Sidemail merges the data and delivers a well‑formatted email.

Can I send emails from Slim middleware?

Yes. Since Sidemail is a standard PHP class, it works anywhere in your Slim app – route handlers, middleware, or standalone scripts. You can use Slim's middleware pattern to decouple email sending from your route logic, for example sending a welcome email after a successful registration response.

Can I schedule an email to send later from Slim?

Yes. Add the scheduledAt field with a future ISO 8601 timestamp to your sendEmail() call. Sidemail queues the message and delivers it at the specified time. You can view or cancel scheduled emails from the dashboard or via the API.

How do I handle email sending errors in Slim?

Wrap your $sidemail->sendEmail() call in a try/catch block and catch Sidemail\SidemailException. The exception provides the HTTP status, error code, and a clear message. You can log it with error_log() or your preferred logger and return an appropriate response.