[thelist] Sending Tabular data with mail()

Ken Schaefer Ken at adOpenStatic.com
Sat May 24 05:41:05 CDT 2008


In the SMTP header you need to specify that the content-type is "multipart/alternative" and what the boundary marker is. You then need to insert the boundary marker to separate out the various "parts" in the multipart message.

That said, I'm surprised that you'd need to use something so primitive to construct a message. Surely there's some other object you can use that allows you to construct a message in a more user friendly way?

Cheers
Ken

> -----Original Message-----
> From: thelist-bounces at lists.evolt.org [mailto:thelist-
> bounces at lists.evolt.org] On Behalf Of Santilal Parbhu
> Sent: Saturday, 24 May 2008 5:01 PM
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] Sending Tabular data with mail()
>
> Thanks Chris,
>
> This just goes to show how little I know about how emails are
> structured.
> Where do you find out about this sort of stuff.
>
> Your solution looks promising.  I take it from your example that you
> have
> two sections: text and html.  The boundary separates the parts.  The
> "\r\n----knabecnarusni\r\n" separates the two sections.
>
> Now, two questions:
>
> Do you have to have "\r\n----knabecnarusni\r\n" at the beginning and
> end of
> each section, and
>
> What exactly is "\r\n----knabecnarusni\r\n" is it something you just
> made up
> or does knabecnarusni mean something.
>
> Thanks for the help.
>
> Santilal
>
> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org] On Behalf Of Chris Price
> Sent: Friday, 23 May 2008 3:05 a.m.
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] Sending Tabular data with mail()
>
> Jeffrey Barke wrote:
> > Santilal,
> >
> > PHP's mail function sends a plain text email, not an HTML one, so no
> > markup is necessary or will work.
> There's nothing stopping you sending html emails using php's mail()
> function but you have to send it multipart.
>
> I set a system up for doing this some years ago and it was rather crude
> but it worked. It looked something like this:
>
> $subject = "myCompany Quotation";
> $to = $emailTo[$value];
>
> $headers = "MIME-Version: 1.0\r\n";
> $headers .= "Content-Type: multipart/alternative;
> boundary=\"--knabecnarusni\"";
> $headers .= "\r\nReturn-Path: <enquiries at myDomain.co.uk>\r\n";
> $headers .= "From: myCompany<enquiry at myDomain.co.uk>\r\n";
> $headers .= "Reply-to: enquiries<enquiries at myDomain.co.uk>";
>
> $message = "This is a multi-part message in MIME format. \r\n";
> $message .= "\r\n----knabecnarusni\r\n";
> $message .= "Content-Type: text/plain; charset=iso-8859-1 \r\n";
> $message .= "Content-Transfer-Encoding: 7bit \r\n\r\n";
>
> $message .= "Quotation from myDomain.co.uk \r\n";
> $message .= "For: $emailForename[$value] $emailSurname[$value]
> \r\n\r\n";
> $message .= "Thank you for using myCompany. A summary of your recent
> enquiry and quotation is listed below: \r\n\r\n";
>
> \/
> \/
>
> $message .= "\r\n----knabecnarusni\r\n";
> $message .= "Content-Type: text/html; charset=iso-8859-1 \r\n";
> $message .= "Content-Transfer-Encoding: 7bit \r\n\r\n";
> $message .= "<html>\r\n";
> $message .= "<body link='#003399' vlink='#003399'
> alink='#003399'>\r\n";
> $message .= "<table cellspacing=0 cellpadding=4 border=0>\r\n";
>
> $message .= "<tr>\r\n";
> $message .= "<td><img
> src='http://www.myDomain.co.uk/email/images/myCompany.gif'
> alt='myCompany'></td>\r\n";
> $message .= "<td align=right width='100%'><img
> src='http://www.myDomain.co.uk/email/images/myimage.gif'
> alt=''></td>\r\n";
>
> $message .= "</td>\r\n";
> $message .= "</tr>\r\n";
> $message .= "</table>\r\n";
> $message .= "</body>\r\n";
> $message .= "</html>\r\n";
>
> $message .= "\r\n----knabecnarusni--\r\n";
>
>
> \/
> \/
>
> mail($To, $Subject, $Message, $Headers);




More information about the thelist mailing list