Integrations

PHP

Official PHP client to send transactional and promotional emails and manage Mailtrap resources.

How it works

The official Mailtrap PHP SDK adds powerful email functionality to any PHP project. Dedicated bridges for Laravel and Symfony to simplify setup without writing code.

Configure

Step 1: Create a Mailtrap account and verify your domain. 

Step 2: Install Mailtrap package via composer. 

Step 3: Send emails, below you’ll find minimal usage example.

<?php

use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapClient;
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;

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

$mailtrap = MailtrapClient::initSendingEmails(
    apiKey: getenv('MAILTRAP_API_KEY') // your API key here https://mailtrap.io/api-tokens
);

$email = (new MailtrapEmail())
    ->from(new Address('sender@example.com'))
    ->to(new Address('recipient@example.com'))
    ->subject('Hello from Mailtrap PHP')
    ->text('Plain text body');

$response = $mailtrap->send($email);

// Access response body as array (helper optional)
var_dump(ResponseHelper::toArray($response));

For Laravel/Symphony bridges, SMTP integration, and advanced usage, see full SDK documentation.

Supported functionality

  • Send transactional and bulk emails with or without templates
  • Manage sending domains 
  • Use Email Sandbox to test emails 
  • Manage Sandbox messages, inboxes, projects 
  • Manage contacts 
  • Manage email templates, suppressions, and account