PHPMailer
Send email from PHP with an authenticated SMTP transport.
Before you begin, verify a sending domain and create an API key. Keep the key in your application server’s secret configuration.
Configure PHPMailer
Install PHPMailer with Composer, then save this script in your project.
Install the package:
composer require phpmailer/phpmailerUse this configuration:
<?php
use PHPMailer\PHPMailer\PHPMailer;
require __DIR__ . '/vendor/autoload.php';
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.usesendy.com';
$mail->Port = 2525;
$mail->SMTPAuth = true;
$mail->Username = 'apikey';
$mail->Password = 'API_KEY';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->CharSet = 'UTF-8';
$mail->setFrom('[email protected]', 'My App');
$mail->addAddress('[email protected]');
$mail->Subject = 'Welcome';
$mail->isHTML(true);
$mail->Body = '<h1>Welcome</h1><p>Your account is ready.</p>';
$mail->AltBody = 'Your account is ready.';
$mail->send();
echo "Email queued.\n"; Replace API_KEY with your full Sendy API key and the sender with an address on your verified domain. Use STARTTLS on port 2525 with the literal username apikey. See PHPMailer email documentation.
Send a test email
php send-email.phpRun php send-email.php. The script prints Email queued. after SMTP accepts the message; failures throw an exception.
Check the result
Open Emails to confirm the message was queued and follow its status. Successful SMTP submission confirms queuing, not inbox delivery. See Errors for failure guidance.