I’m doingsome tests, I tried two solutions so far:
The first one sends the message inside the headers (message parameter of the mail() function is empty) []
$boundary = "nextPart";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: ".$from_name." <".$from.">\r\n";
$headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n";
//Html
$headers .= "\n--$boundary\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= $html;
//Text
$headers .= "\n--$boundary\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= $text;
The second one is this one: http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment (set headers and sends them inside the message)
Non of them works properly (the first one doesn’t work at all, the second works in gmail but it’s not a properly formatted email, and some client can’t handle it).
Dissecting the code of php mailer (http://phpmailer.worxware.com/index.php?pg=phpmailer) i saw that it doesn’t even try to send multipart emails.
So I’m wondering is it possible to send PROPERLY formatted multipart email with the php mail function.
Thank you
p.s. I know and use pear mail, I just want to understand this thing.
yes, it is possible. PHP’s
mail();function is nothing more than a handy function to deliver your ‘raw’ message to the underlying operating system’s mail handler (sendmail for example).So if your message headers- and message body combined are a correct MIME encoded message, things will work fine.
To figure out the details, find a simple mail client and analyse it’s emails. Combine this with the MIME specifications and you should get there.