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
composer require phpmailer/phpmailerSend with STARTTLS (587)
<?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)
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;Good to know
setFrommust use an address on a verified domain of your organization, otherwise usend answers554.- Keep certificate verification on (the default). Do not set
SMTPOptionswithverify_peer => false: the server presents a valid certificate forsmtp.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-ToandList-Unsubscribeare 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.