Simple setup & reliable delivery

Send email in PHP

Add email sending to your PHP application in minutes using Sidemail's clean API and official PHP SDK. Sidemail takes care of deliverability, authentication, and infrastructure so your PHP code simply calls an API and your users get the email in their inbox.

Get startedRead API docs
Send a welcome email template
$sidemail->sendEmail([
	'toAddress'     => $user['email'],
	'fromAddress'   => '[email protected]',
	'fromName'      => 'Your App',
	'templateName'  => 'Welcome',
	'templateProps' => [
		'firstName' => $user['name'],
	],
]);

Quickstart: Send email in PHP

Three steps to start sending emails from your PHP app:

1

Install the Sidemail PHP SDK

Add Sidemail to your project with Composer:

composer require sidemail/sidemail
2

Initialize the client

Require the autoloader and create a Sidemail instance. The SDK automatically reads SIDEMAIL_API_KEY from your environment.

require_once __DIR__ . '/vendor/autoload.php';

use Sidemail\Sidemail;

$sidemail = new Sidemail();
// or with explicit key: new Sidemail(apiKey: 'your-api-key');
3

Send your first email

Call the sendEmail method with recipient, sender, and either a template name or raw content. That is all it takes to send email from PHP through Sidemail's API.

// Example: send a welcome email template
$sidemail->sendEmail([
	'toAddress'     => '[email protected]',
	'fromAddress'   => '[email protected]',
	'fromName'      => 'Your App',
	'templateName'  => 'Welcome',       // template stored in Sidemail
	'templateProps' => ['firstName' => 'Alice'], // dynamic data for the template
]);

Key features & perks

Why Sidemail for PHP emails

  • Quick PHP email integration

    Start sending emails from PHP in minutes. Install the official Composer package, initialize with your API key, and call one method. Sidemail's PHP SDK is designed so you can go from zero to sending in under 30 minutes, with clear docs and ready‑to‑use code examples.
  • Reliable inbox delivery

    Sidemail's infrastructure and sender vetting process make sure your emails reach inboxes consistently. No more worrying about spam filters, IP reputation, or deliverability. Just reliable email delivery that works.
  • Custom sending domain with DKIM & SPF

    Send from your own domain without the hassle of manual DNS configuration. Sidemail automatically sets up DKIM and SPF authentication for you. These are two of the most important factors for strong inbox placement and sender reputation.
  • Complete email platform in one place

    Sidemail is more than a sending API. It handles transactional emails, newsletters, email automation, contacts collection and management. Your PHP code talks to one API while the dashboard lets you design templates, manage contacts, and analyze performance in the same place.
  • Premade templates & no‑code email editor

    Choose from a library of production‑ready email templates that render perfectly across every inbox and device. Want something custom? The no‑code editor lets you build or modify responsive email templates visually, without writing any HTML.
  • A better alternative to PHP mail()

    PHP's native mail() function can be unreliable, hard to debug, and gives you zero visibility into what happens after sending. Sidemail provides you with a modern API, detailed delivery logs, unlimited sending history, and fast and reliable deliverability. It is the upgrade your PHP app deserves.

PHP transactional email examples

Sidemail makes it easy to send any transactional email from PHP. Here are a few common examples:

// PHP: Send a password reset email using a Sidemail template
$sidemail->sendEmail([
	'toAddress'     => $user['email'],
	'fromAddress'   => '[email protected]',
	'fromName'      => 'Your App',
	'templateName'  => 'Password Reset',
	'templateProps' => [
		'actionUrl' => 'https://yourapp.com/reset?token=' . $token,
	],
]);

Password reset email

Send a secure password reset link when a user submits the forgot password form.

  • Include a clear call‑to‑action button and make sure the reset link expires after a set time for security.
  • Sidemail provides a ready‑made password reset template you can use right away.
See password reset email template
// PHP: 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('F j, Y'),
	],
]);

Receipt or invoice email

Automatically send a receipt or invoice after a successful payment.

  • Include all relevant details like the amount, date, and item description so users have a complete record.
  • Sidemail's receipt and invoice templates accept dynamic data via templateProps to populate amounts, names, and line items.
See receipt email template
// PHP: Schedule a welcome email for 1 hour from now
$scheduledAt = (new DateTime('+1 hour'))->format(DateTime::ATOM);

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

Welcome email with scheduled delivery

Schedule a welcome email to arrive later, for example one hour after the user signs up.

  • Set the scheduledAt field to an ISO 8601 timestamp to control exactly when the email is delivered.
  • Great for onboarding flows where you want to give the user some time in your app before sending the first message.
See welcome email template
// PHP: Send a security alert email with Markdown content
$markdown = file_get_contents(
	__DIR__ . '/templates/emails/security-alert.md'
);

$sidemail->sendEmail([
	'toAddress'     => '[email protected]',
	'markdown'      => $markdown,
	'templateProps' => [
		'name'       => $user['name'],
		'device'     => 'MacBook Pro',
		'location'   => 'Berlin, Germany',
		'reviewLink' => 'https://yourapp.com/security/activity',
	],
]);
---
subject: "Security alert: new login detected"
fromAddress: "[email protected]"
fromName: "Your App Security"
---

Hi {name},

We noticed a new login from **{device}** in **{location}**.

[$btn Review security activity]({reviewLink})

If this was not you, please reset your password now.

Security alert email with Markdown

Use Markdown to send clear security notifications when a login event needs user attention. Sidemail converts your Markdown to responsive HTML and keeps the final email aligned with your project branding.

  • Store your email content in a .md file
  • Subject and sender are defined in the markdown frontmatter.
  • Use templateProps to inject dynamic values like device, location, and review links directly into your markdown content.

Deliverability best practices

SPF, DKIM, and DMARC for transactional email

SPF, DKIM, and DMARC are email authentication protocols that prove your messages are legitimately sent from your domain. Together, they are the three most important factors for inbox placement and protecting your sender reputation.

Sidemail sets up SPF, DKIM, and DMARC for you automatically. So, your PHP application sends fully authenticated emails from day one, with no manual DNS work required.

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

Create responsive email templates with Sidemail's visual editor. No HTML knowledge needed. Pick your brand colors, add your logo, and start sending professional emails in minutes.

Need to move faster? Use one of Sidemail's premade templates for common use cases like password resets, welcome emails, and receipts. Every template is tested across all major email clients and devices, so your emails always look great. Whether you build your email from scratch or customize a premade template, the result is pixel‑perfect every time.

Learn more

Developer‑friendly formatting

Markdown support for PHP emails

Building and maintaining HTML emails by hand is painful. When you just need to send clean, readable content, it should not require fighting with inline styles and table layouts.

Sidemail lets you write your email content in Markdown and converts it into a responsive, well‑styled HTML email automatically. Headings, lists, links, code blocks, buttons, and more, all work out of the box.

Perfect for transactional emails sent from PHP. Clean content, fast authoring, zero HTML to debug.

Learn more
Markdown email code example and rendered preview

Get started today

Ready to send transactional emails from PHP? Sidemail's API and official PHP SDK make it easy to integrate in minutes and deliver emails reliably.

Start free trial

FAQs

How do I send email in PHP?

The simplest way to send email in PHP is with an email API like Sidemail. Install the PHP SDK (composer require sidemail/sidemail), initialize the client, and call the sendEmail() method. No SMTP configuration, no server setup, no unreliable mail() calls. Sidemail handles authentication, formatting, and deliverability for you.

Why should I use Sidemail instead of PHP mail()?

PHP's built‑in mail() function depends on your server's local mail configuration, often sends emails that land in spam, and gives you no visibility into delivery status. Sidemail replaces it with a modern API that includes automatic DKIM and SPF setup, detailed delivery logs, unlimited email history, premade templates, and reliable inbox placement. It is a significant upgrade with very little code change required.

How do I use email templates with Sidemail in PHP?

Create or import a template in the Sidemail dashboard using the drag‑and‑drop editor or premade library. Then in PHP, reference the template by name via templateName and pass personalization data through templateProps. For example, a "Welcome" template with a {firstName} variable can be sent with 'templateProps' => ['firstName' => 'Alice']. Sidemail merges the data and delivers a professionally styled email.

Can I send attachments in PHP emails with Sidemail?

Yes. The PHP SDK includes a Sidemail::fileToAttachment() helper. Read the file contents with file_get_contents() and pass it along with the filename. Include the result in the attachments array. Supported file types include PDF, PNG, JPG, and CSV. Keep total attachment size under about 2.5 MB for best results.

Can I schedule an email to send later from PHP?

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

Does Sidemail work with Laravel, Symfony, and other PHP frameworks?

Yes. The Sidemail PHP SDK works with any PHP project, including Laravel, Symfony, Slim, WordPress, and plain PHP scripts. Install via Composer, initialize the client, and call sendEmail(). Sidemail also provides dedicated guides for Laravel, Symfony, and Slim.

How do I handle errors when sending email in PHP?

Wrap your sendEmail() call in a try‑catch block and catch Sidemail\SidemailException. The exception message gives you details about what went wrong. Log the error with error_log() or send it to your monitoring system for visibility.