SMTP
PHPMailer (SMTP)
Send your first email from PHP with PHPMailer over the MailBlastr SMTP relay.
If your PHP app already uses PHPMailer, you can send through MailBlastr over SMTP. Point PHPMailer at the MailBlastr relay and authenticate with your API key. SMTP sends appear in your dashboard and event log just like API sends.
Prerequisites
- A MailBlastr API key.
- A verified domain to send from.
1. Install
Add the phpmailer/phpmailer package with Composer.
composer require phpmailer/phpmailer2. SMTP credentials
Configure PHPMailer with the following credentials:
Hoststringoptionalsmtp.mailblastr.com
Portnumberoptional587 (STARTTLS) or 465 (implicit TLS).
Usernamestringoptionalmailblastr
PasswordstringoptionalYour API key, e.g. mb_xxxxxxxxx.
3. Send email using SMTP
Use those credentials to send. The setFrom address must be on a verified domain.
<?php
// Include Composer autoload file to load PHPMailer classes
require __DIR__ . '/vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtp.mailblastr.com';
$mail->SMTPAuth = true;
$mail->Username = 'mailblastr';
$mail->Password = 'mb_xxxxxxxxx';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Set email format to HTML
$mail->isHTML(true);
$mail->setFrom('onboarding@yourdomain.com');
$mail->addAddress('delivered@example.com');
$mail->Subject = 'Hello World';
$mail->Body = '<strong>It works!</strong>';
$mail->send();
// Log the successfully sent message
echo 'Email successfully sent';
} catch (Exception $e) {
// Log the detailed error for debugging
error_log('Mailer Error: ' . $mail->ErrorInfo);
// Show a generic error message to the user
echo 'There was an error sending the email.';
}For implicit TLS, set
$mail->SMTPSecure = 'ssl'; and $mail->Port = 465;. See Send an email if you would rather use the HTTP API.