PHP
Integrate Mailtrap with PHP applications using SDK, SMTP, or RESTful API for reliable email sending
Last updated
Was this helpful?
Was this helpful?
composer require railsware/mailtrap-php<?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/settings/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));