PHP (PHPMailer)
PHPMailer against a sandbox, without a framework in the way.
Prerequisites
- PHP 7.4 or later
- phpmailer/phpmailer
1Install PHPMailer
composer require phpmailer/phpmailer2Send a test message
<?php use PHPMailer\PHPMailer\PHPMailer; require 'vendor/autoload.php'; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.mailclutch.com'; $mail->Port = 587; $mail->SMTPAuth = true; $mail->Username = 'mc_0000000000000000'; $mail->Password = 'pw_0000000000000000'; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->setFrom('staging@example.com'); $mail->addAddress('anyone@example.com'); $mail->Subject = 'Sandbox check'; $mail->isHTML(true); $mail->Body = '<h1>Hello from PHP</h1>'; $mail->send();
Watch it land
Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.
Nothing is ever delivered onward, whatever address you send to; claim the sandbox with an account and it stays.
Awaiting your email
Send from any address; it stops here rather than going onward. The sandbox keeps what it catches for 24 hours.
Go further
PHP mail()
PHP's
mail()hands the message to a local binary, which has no idea about SMTP credentials. Either send through PHPMailer or Symfony Mailer, or relay the local MTA — see the Postfix guide.SMTPDebug
$mail->SMTPDebug = 2;prints the whole conversation, which usually names the problem on the first line.
Other stacks
The same four values in another dialect. Every guide below is filled in with the sandbox pair at the top of this page.
Frameworks and languages
- LaravelFive .env variables, no package
- SymfonyOne MAILER_DSN
- DjangoFive settings, nothing installed
- RailsAction Mailer smtp_settings
- Node.jsA Nodemailer transport
- Next.jsRoute Handler or Server Action
- Gonet/smtp, standard library
- SpringFive Spring Boot properties
- JavaJakarta Mail, no framework
- .NETMailKit: connect, auth, send
- Pythonsmtplib, standard library
- Rustlettre over a STARTTLS relay