uSend Docs
SMTP guides

PHPMailer

Send through usend from PHP with PHPMailer over SMTP.

Settings used on this page: host smtp.usend.et, port 587 (STARTTLS) or 465 (implicit TLS), username usend, password your API key. The full reference is Send with SMTP.

Install

Shell
composer require phpmailer/phpmailer

Send with STARTTLS (587)

send.php
<?php
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;

require 'vendor/autoload.php';

$mail = new PHPMailer(true); // true: throw exceptions

try {
    $mail->isSMTP();
    $mail->Host       = 'smtp.usend.et';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'usend';
    $mail->Password   = getenv('USEND_API_KEY');
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port       = 587;

    $mail->setFrom('[email protected]', 'Acme');
    $mail->addAddress('[email protected]');
    $mail->addReplyTo('[email protected]');

    $mail->isHTML(true);
    $mail->Subject = 'Hello from usend';
    $mail->Body    = '<p>It works!</p>';
    $mail->AltBody = 'It works!';
    $mail->addAttachment('invoice.pdf');

    $mail->send();
    echo "Sent\n";
} catch (Exception $e) {
    echo "Failed: {$mail->ErrorInfo}\n";
}

Implicit TLS (465)

PHP
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port       = 465;

Good to know

  • setFrom must use an address on a verified domain of your organization, otherwise usend answers 554.
  • Keep certificate verification on (the default). Do not set SMTPOptions with verify_peer => false: the server presents a valid certificate for smtp.usend.et.
  • To debug, set $mail->SMTPDebug = 2; temporarily. It prints the conversation, including the base64-encoded credentials, so never leave it on in production logs.
  • X- headers, Reply-To and List-Unsubscribe are kept; other custom headers are replaced by usend's own.
  • If port 587 is blocked on your host, try 465, or use the REST API over HTTPS.