Re: [PHP-DB] MIME Alternatimve Emails

[email protected] (Richard Quadling)
Newsgroups php.db
Message-ID <[email protected]>
On 30 January 2010 13:23, Karl DeSaulniers <[email protected]> wrote:
> Thanks Richard for your response,
> Since the code is a little long, I didn't want to post too much, so
> I just put the last part with the headers I was using.
> also, since the mailer worked previously,
> I was thinking it was just the new header info I was plugging in
> so to do the whole checking if a user can receive HTML emails or text.
>
> Any thoughts on what order I should be putting the headers I have?
> TIA,
>
> Karl
>
>
> On Jan 30, 2010, at 7:13 AM, Richard Quadling wrote:
>
>> On 30 January 2010 13:04, Karl DeSaulniers <[email protected]> wrote:
>>>
>>> Hi List,
>>> Good morning. Hope all are well on this Saturday.
>>> I am in  need of a little assistance. I am creating an HTML email.
>>> I have created it successfully already, so I know the code works for the
>>> HTML part.
>>> My question is about the headers of the message.
>>>
>>> Here is my code at the end before the message is sent off.
>>>
>>> //other code  that sets up $html and $text
>>>
>>> if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
>>>         $eol="\r\n";
>>>       } else if (strtoupper(substr(PHP_OS, 0, 3) == 'MAC')) {
>>>        $eol="\r";
>>>       } else {
>>>         $eol="\n";
>>> }
>>>
>>> // To send HTML mail, the Content-type header must be set
>>> $headers = 'From: '.$from.$eol;
>>> $headers .= 'To: "'. $username .'" <' . $email . '>'.$eol;
>>>
>>> //$headers .= 'Cc: ' . $from;
>>> //$headers .= 'BCc: ' . $from;
>>> $headers .= 'Reply-To: ' . $from .$eol;
>>>
>>> $headers .= 'X-Mailer: PHP/' . phpversion().$eol;
>>> $headers .= 'X-sender: <' . $from . '>'.$eol;
>>> $headers .= 'X-receiver: <' . $email . '>'.$eol;
>>>
>>> $headers .= 'Message-ID: <'.$MessageID.'@'.$host.'>'.$eol;
>>> $headers .= 'Date: '.$time.$eol;
>>>
>>> // Additional headers
>>> $headers .= 'X-Priority: 1'.$eol;
>>> $headers .= 'X-MSMail-Priority: High'.$eol;
>>> $headers .= 'X-MimeOLE: Generated By Design Drumm - MultiPart/Alt
>>> E-Mail'.$eol;
>>>
>>> $headers .= 'MIME-Version: 1.0' . $eol;
>>> $headers .= 'Content-type: multipart/alternative';
>>> $headers .= 'boundary="'.$boundary.'"' . $eol.$eol;
>>>
>>> // Make sure there are no bare linefeeds in the headers
>>> //$headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);   //I found
>>> this code. Can anyone tell me if it works.
>>>
>>> $message = '--'.$boundary.$eol;
>>> $message .= 'Content-type: text/html; charset="UTF-8"'.$eol;
>>> $message .= 'Content-Transfer-Encoding: 8bit'.$eol.$eol;
>>> $message .= $html.$eol.$eol;
>>>
>>> $message .= '--'.$boundary.$eol;
>>> $message .= 'Content-type: text/plain; charset="UTF-8"'.$eol;
>>> $message .= 'Content-Transfer-Encoding: quoted-printable'.$eol.$eol;
>>>
>>> $message .= $text.$eol.$eol;
>>> $message .= '--'.$boundary.'--'.$eol.$eol;
>>>
>>> return mail($email, $subject, $message, $headers);
>>>
>>>  }
>>>
>>> My question is what order should the headers be in from top to bottom
>>> that I
>>> have to work properly?
>>> Currently it does not display the HTML on MAC but it does in Hotmail. MAC
>>> mail is grabbing the text version.
>>> So my susspicion is that the headers are just wrong.
>>>
>>> It has worked on MAC mail before I tried the MIME boundaries.
>>>
>>> TIA,
>>>
>>>
>>> Karl DeSaulniers
>>> Design Drumm
>>> http://designdrumm.com
>>>
>>>
>>
>> I would simplify all of this by using a PHP class specifically
>> covering this issue.
>>
>> I use the html_mime_mail5 class from phpguru.org (now called RMail) at
>> http://www.phpguru.org/static/Rmail
>>
>> Though, you'll probably find PHPMailer is the most commonly used class
>> at http://phpmailer.worxware.com/
>>
>> --
>> -----
>> Richard Quadling
>> "Standing on the shoulders of some very clever giants!"
>> EE : http://www.experts-exchange.com/M_248814.html
>> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
>> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
>> ZOPA : http://uk.zopa.com/member/RQuadling
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
>

I use RMail. With that ...

$RMail->addText($TextMessage);
$RMail->addHTML($HTMLMessage, $DirForImages);

That's it.

If the client can only read text, it will show the text. Otherwise it
will show the HTML.

The alternative headers are all taken care of by the class.
-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.