Skip to content

Instantly share code, notes, and snippets.

@tott
Created October 16, 2018 21:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tott/a10bebe067d517455e423eb32f7d1d3d to your computer and use it in GitHub Desktop.
Sending multipart mail with wp_mail (untested)
<?php
$to = "receipt@domain.com";
$subject = "My Multipart test";
$message = "I am the plain text message";
$boundary = uniqid(rand(), true);
$header = "MIME-Version: 1.0\n"
$header .= "Content-Type: multipart/alternative; boundary=\"$boundary\"\n";
$multipart_message = "
--$boundary
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
$message
--$boundary
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
<html>
<head>
<style type=\"text/css\">
</style>
</head>
<body style=\"margin: 0; padding: 0; background: #fff;-webkit-text-size-adjust:100%;\">
<span style=\"color: white; font-size: 12px; display: none;\">$message</span>
</body>
</html>
--$boundary--
";
wp_mail( $to, $subject, $multipart_message, $header );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment