I can send just text fine, just html fine, but when I combine the two as follows the email sends but the body is empty.
$to = "some@email.com";
$subject = "Welcome";
$boundary = md5(date('U'));
$headers = "From: Company <noreply@email.com>" . "\n".
"X-Mailer: PHP/".phpversion() ."\n".
"MIME-Version: 1.0" . "\n".
"Content-Type: multipart/alternative; boundary=".$boundary. "\n";
"Content-Transfer-Encoding: 7bit". "\n";
// TEXT EMAIL PART
$text = "Congratulations";
// HTML EMAIL PART
$html = "<html><body>\n";
$html .= "<div>Congratulations</div>";
$html .= "</body></html>\n";
$message = "Multipart Message coming up" . "\n\n".
"--".$boundary.
"Content-Type: text/plain; charset=\"iso-8859-1\"" .
"Content-Transfer-Encoding: 7bit".
$text.
"--".$boundary.
"Content-Type: text/html; charset=\"iso-8859-1\"".
"Content-Transfer-Encoding: 7bit".
$html.
"--".$boundary."--";
mail($to, $subject, $message, $headers);
You’ve forgotten line breaks after your Content-Type and Content-Transfer-Encoding lines, so the beginnings of your body content are co-mingled with the headers:
As stated in the comments above, use Swiftmailer or PHPMailer to do this. They’ll take care of all the piddle little details, and let you send the entire mail in far fewer lines of code.