Send HTML and Plain-Text Email in One Message

Last updated: August 29, 2026.

A multipart message lets capable clients display HTML while other clients and accessibility tools receive a clean text alternative. Both parts should contain the same essential information.

Set both message bodies

<?php
require __DIR__ . '/vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
$mail = new PHPMailer(true);
// Configure SMTP, sender, and recipient first.
$mail->isHTML(true);
$mail->Subject = 'Weekly summary';
$mail->Body = '<h1>Weekly summary</h1><p>Your report is <a href="https://example.com/report">ready</a>.</p>';
$mail->AltBody = "Weekly summary\n\nYour report is ready: https://example.com/report";
$mail->send();

Keep email HTML conservative

  • Use meaningful link text.
  • Escape all user-provided values.
  • Include useful alt text for images.
  • Test several major mail clients.

Keep both alternatives equivalent

The plain-text part should contain the same essential message, links, dates, and actions as the HTML version. It is not merely a fallback sentence; some recipients and security tools rely on it.

Send test messages to clients that prefer each alternative and inspect the raw MIME structure. Verify that user-supplied values are escaped for HTML and remain readable in plain text.

  • Use absolute HTTPS links.
  • Include useful image alt text.
  • Avoid CSS that common mail clients remove.

Keep resource limits explicit and make failure cleanup part of the example. Log enough context to diagnose the operation without recording passwords, private message bodies, or uploaded file contents.

Continue with SMTP with PHPMailer, UTF-8 email, and existing PHP email guide.

Practical implementation check

Put the operation in a small function or service with explicit inputs and a clear failure result. Test invalid input, missing extensions, permission failures, and concurrent requests. Production logs should identify the operation and record ID without storing secrets or private content. Clean up partially created files or queue records when any later step fails.

Return a clear result to the caller and keep user-facing messages separate from detailed diagnostics. This makes the same code usable from a web request, command-line job, or queue worker.

Reference: PHPMailer official repository.

admin

admin