Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building an HTML email from scratch

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
I'm writing a PHP application that builds and email from scratch in which I am trying to use HTML. The documention seems pretty clear but since it is not working, I am obviously missing something. This is a simple email that is built using pure HTML. The headers I add to the email that I thought should work are:
Code:
MIME-version: 1.0
Content-type: text/html
This email then is either thrown away with some error (it is displayed too briefly to read) by one reader or simply displays the HTML tags as text in others. What am I doing wrong? TIA.
 
don't know if this helps but below is the source for my html emails
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2604" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>&nbsp;</DIV></BODY></HTML>
 
Thanks for the reply.

That is pretty much what I have for my content but that is not the problem. All those tags are displayed simply as text. The issue is, which apparently is being done automagically for you somehow, is the email headers that tells the reader that the content is HTML format rather then plain text.

Could you post the raw headers for one of those emails?
 
this is how the mail server sets it. i X'd out the identifyer in the "NextPart"

MIME-version: 1.0
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
Content-type: multipart/mixed;
boundary="----=_NextPart_XXX_XXXX_XXXXXXXX.XXXXXXXX"
X-Priority: 3
X-MSMail-priority: Normal
 
Thanks again.

This is getting frustrating. It looks pretty much the same as mine. The crux of my problem debugging this is that my stupid reader keeps flashing an error too fast to read then then throwing away the email so I can't see what it is unhappy with. When I use Unix 'mail' to read it, everything looks fine but unfortunately, 'mail' is text only.
 
don't forget, that even though you write it in html, if the reciever does not have html enabled on their machine you are stil only sending text!
 
I finally got it working. The problem turned out to be the extremely fussy way headers need to be set up (to a fault, IMO). It also was compounded by the way PHP 'mail()' works.

The spacing of headers and boundry lines is critial (i.e. there cannot be a blank line between the boundry line and the content-type line and there MUST be a blank line between the content-type line and text of that part of the body.

The crux of the problem was that the headers need to be terminated with '\r\n' which I already knew. However, when the boundry and header are part of the body, the '\r\n' is apparently not recognized by the 'mail()' function and thus not properly translated. The solution was to put chr(13) and chr(10) at the end of those lines when in the body.

Sheesh!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top