True\Email sends mail over SMTP with a fluent builder. It speaks plain SMTP, SSL, and TLS, supports attachments, DKIM signing, and HTML/plaintext multipart bodies.
Connect
Pass the SMTP host, port, protocol, and auth method to the constructor:
$mail = new \True\Email(
'smtp.example.com', // host
587, // port
'tls', // 'ssl' | 'tls' | ''
'login' // 'plain' | 'login' | 'cram-md5'
);
$mail->setLogin('postmaster@example.com', 'secret');
Send a message
$mail
->setFrom('hello@example.com', 'Acme')
->addTo('user@example.com', 'Daniel')
->setSubject('Welcome')
->setHtmlMessage('<h1>Hello</h1><p>Thanks for signing up.</p>')
->setTextMessage('Hello — thanks for signing up.');
if (!$mail->send()) {
error_log(print_r($mail->getLogs(), true));
}
Recipients
$mail->addTo ('a@example.com', 'Alice');
$mail->addCc ('b@example.com');
$mail->addBcc('c@example.com');
$mail->setReplyTo('support@example.com', 'Support');
Attachments
$mail->addAttachment(BP.'/app/data/invoice.pdf');
Template variables
Place placeholders in the HTML body and pass a substitution map. Each {{key}} is replaced before send:
$mail->setHtmlMessage('<p>Hi {{first_name}}, your code is {{code}}.</p>')
->setHTMLMessageVariables([
'first_name' => 'Daniel',
'code' => '8421',
]);
DKIM signing
$mail->addDKIM(BP.'/app/data/dkim.private', 'example.com');
Custom headers
$mail->addHeader('X-Tag', 'welcome-flow');
Inspecting failures
send() returns true on success, false on any failure. The full SMTP transcript is available afterward:
$ok = $mail->send();
if (!$ok) print_r($mail->getLogs());
For volume sending or bounce handling, route mail through Amazon SES, Postmark, or another transactional provider — True\Email works fine against any SMTP relay they expose.