views:

37

answers:

2

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.

+1  A: 

From what i know, mail() just sends what it's given, so yes, it's perfectly possible to send whatever you want, including multipart mimes. In fact, this is exactly what mail classes (pear, phpmailer) do behind the scenes, although they can be configured to use other transports as well.

In other words, a mail class compares to "mail()" like a template engine compares to "echo".

stereofrog
+2  A: 

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.

Jacco