Connecting Tech Pros Worldwide Help | Site Map

HTML Mail

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 12th, 2006, 04:45 AM
J Huntley Palmer
Guest
 
Posts: n/a
Default HTML Mail

How may I setup a proper HTML mail message with embedded href links
using PHP, that follows all the MIME rules? Any examples or links would
be appreciated.

Thanks!

  #2  
Old May 12th, 2006, 05:15 AM
NC
Guest
 
Posts: n/a
Default Re: HTML Mail

J Huntley Palmer wrote:[color=blue]
>
> How may I setup a proper HTML mail message with embedded
> href links using PHP, that follows all the MIME rules?[/color]

Check out phpMailer: http://phpmailer.sf.net/

Cheers,
NC

  #3  
Old May 12th, 2006, 03:35 PM
robert
Guest
 
Posts: n/a
Default Re: HTML Mail

"J Huntley Palmer" <jhp@dontspam.spam> wrote in message
news:12684lgilbtrga5@news.supernews.com...
| How may I setup a proper HTML mail message with embedded href links
| using PHP, that follows all the MIME rules? Any examples or links would
| be appreciated.

many will post links to full-featured php mailer classes...they tend to be
over-blown. here's what i use...if you understand the rfc, modifying the
code below is easily done so that this can handle attachements as well.
actually, this already has an attachement in it...you would use the same
methodology as seen when a logo is added to the below.

hth,

me


======== email.class.php (php 5)

// $dropDirectory w/b like 'c:/inetpub/mailroot/pickup/' for iis on windows
// anywhere you'd like for unix
// $exec w/b if php shelled out to sendmail, qmail, or whatever.

<?
class email
{
static function send(
$to ,
$from ,
$cc = '' ,
$bcc = '' ,
$subject ,
$text ,
$html = '' ,
$companyName = '' ,
$logo = null ,
$dropDirectory = '' ,
$exec = null
)
{
// prevent email injection hacks
$subject = preg_replace("/\nfrom\:.*?\n/i" , "", $subject);
$subject = preg_replace("/\nbcc\:.*?\n/i" , "", $subject);
$subject = preg_replace("/\ncc\:.*?\n/i" , "", $subject);
$text = preg_replace("/\nfrom\:.*?\n/i" , "", $text);
$text = preg_replace("/\nbcc\:.*?\n/i" , "", $text);
$text = preg_replace("/\ncc\:.*?\n/i" , "", $text);
$html = preg_replace("/\nfrom\:.*?\n/i" , "", $html);
$html = preg_replace("/\nbcc\:.*?\n/i" , "", $html);
$html = preg_replace("/\ncc\:.*?\n/i" , "", $html);
//
$messageHtml = $html;
$html = '
<html>
<style>
body
{
background-color : #FFFFFF;
color : black;
font-family : verdana, tahoma, arial, times new
roman, sans-serif;
font-size : 8pt;
padding : 2px;
text-align : left;
}
hr
{
background-color : lightsteelblue;
border : 0px;
color : lightsteelblue;
height : 1px;
}
table
{
border-collapse : collapse;
border-padding : 2px;
border-width : 0px;
border-spacing : 0px;
width : 700px;
}
td
{
background-color : #FFFFFF;
color : black;
font-family : verdana, tahoma, arial,
"times new roman", sans-serif;
font-size : 8pt;
margin : 5px;
padding-left : 5px;
padding-right : 5px;
spacing : 0px;
text-align : left;
vertical-align : top;
}
th
{
background-color : lavender;
color : black;
font-family : verdana, tahoma, arial,
"times new roman", sans-serif;
font-size : 8pt;
font-weight : bold;
margin : 5px;
text-align : left;
}
</style>
<body>
';
if (isset($logo))
{
$file = @fopen($logo, 'r');
$image = @fread($file, filesize($logo));
$image = @chunk_split(base64_encode($image));
@fclose($file);
unset($file);
$html .= '
<img alt="' . $companyName . '" border="0px"
src="cid:logo" style="float:right;">
<br>
<br>
<br>
<br clear="all">
';
}
if ($messageHtml == ''){ $messageHtml = $text; }
$html .= $messageHtml . '</body></html>';
$boundry = '----=' . md5(uniqid(rand()));
$related = '----=' . md5(uniqid(rand()));
$mail = "MIME-Version: 1.0\r\n";
$mail .= "TO: " . $to . "\r\n";
$mail .= "FROM: " . $from . "\r\n";
$mail .= "CC: " . $cc . "\r\n";
$mail .= "BCC: " . $bcc . "\r\n";
$mail .= "Subject: " . $subject . "\r\n";
$mail .= "content-type: multipart/related;
boundary=\"$related\"\r\n\r\n\r\n";
$mail .= "--$related\r\n";
$mail .= "content-type: multipart/alternative;
boundary=\"$boundry\"\r\n\r\n\r\n";
$mail .= "--$boundry\r\n";
$mail .= "content-type: text/plain; charset=\"iso-8859-1\"\r\n";
$mail .= "content-transfer-encoding: 8bit\r\n\r\n";
$mail .= $text . "\r\n\r\n";
$mail .= "--$boundry\r\n";
$mail .= "content-type: text/html; charset=\"iso-8859-1\"\r\n";
$mail .= "content-transfer-encoding: 8bit\r\n\r\n";
$mail .= $html . "\r\n\r\n";
$mail .= "--$boundry--\r\n\r\n";
$mail .= "--$related\r\n";
$mail .= "content-type: image/jpeg\r\n";
$mail .= "content-id: logo\r\n";
$mail .= "content-disposition: attachment;
filename=\"logo.jpg\"\r\n";
$mail .= "content-transfer-encoding: base64\r\n\r\n";
$mail .= $image . "\r\n\r\n";
$mail .= "--$related--\r\n\r\n";
$mail .= "-- End --\r\n";
$fileName = $dropDirectory . md5(uniqid(rand())) . '.eml';
$file = fopen($fileName, 'wb');
fwrite($file, $mail);
fclose($file);
unset($file);
if (!isset($exec)){ return $mail; }
exec($exec . $fileName);
return $mail;
}
}
?>


  #4  
Old May 14th, 2006, 12:45 AM
Alan Little
Guest
 
Posts: n/a
Default Re: HTML Mail

Carved in mystic runes upon the very living rock, the last words of
robert of comp.lang.php make plain:
[color=blue]
> "J Huntley Palmer" <jhp@dontspam.spam> wrote in message
> news:12684lgilbtrga5@news.supernews.com...
>| How may I setup a proper HTML mail message with embedded href links
>| using PHP, that follows all the MIME rules? Any examples or links
>| would be appreciated.
>
> many will post links to full-featured php mailer classes...they tend
> to be over-blown. here's what i use...if you understand the rfc,
> modifying the code below is easily done so that this can handle
> attachements as well. actually, this already has an attachement in
> it...you would use the same methodology as seen when a logo is added
> to the below.[/color]

Just wondering -- how extensively has this code been used and tested? One
of the most aggravating things I've encountered is the HTMLMail plugin
for Phorm. I wrote the code, based on the RFCs, and for the most part it
works fine. But some installations of OE have trouble with it. Only some,
which is the aggravating part. I installed OE to check it out, and of
course it works fine for me, so I haven't been able to troubleshoot it.

Of course, it's been two and a half years since I looked at the code, so
maybe I should go back and see if I've learned anything in that time.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
  #5  
Old May 15th, 2006, 02:45 AM
robert
Guest
 
Posts: n/a
Default Re: HTML Mail


"Alan Little" <alan@n-o-s-p-a-m-phorm.com> wrote in message
news:Xns97C2D301EC2A3alanphormcom@216.196.97.131.. .
| Carved in mystic runes upon the very living rock, the last words of
| robert of comp.lang.php make plain:
|
| > "J Huntley Palmer" <jhp@dontspam.spam> wrote in message
| > news:12684lgilbtrga5@news.supernews.com...
| >| How may I setup a proper HTML mail message with embedded href links
| >| using PHP, that follows all the MIME rules? Any examples or links
| >| would be appreciated.
| >
| > many will post links to full-featured php mailer classes...they tend
| > to be over-blown. here's what i use...if you understand the rfc,
| > modifying the code below is easily done so that this can handle
| > attachements as well. actually, this already has an attachement in
| > it...you would use the same methodology as seen when a logo is added
| > to the below.
|
| Just wondering -- how extensively has this code been used and tested? One
| of the most aggravating things I've encountered is the HTMLMail plugin
| for Phorm. I wrote the code, based on the RFCs, and for the most part it
| works fine. But some installations of OE have trouble with it. Only some,
| which is the aggravating part. I installed OE to check it out, and of
| course it works fine for me, so I haven't been able to troubleshoot it.

i've used the same code for three companies over the past few years for
automatic emails of various communications like general messaging, system
error reporting, scheduled reporting with and without attached files like
pdf's and excel.

so far, so good. ;^) one system is windows based, the other two are linux
and unix systems.


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.