Home Forums OS X Server and Client Discussion Mail Building an HTML email from scratch

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #360948
    gw1500se
    Participant

    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:

    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 Applemail or simply displays the HTML tags as text in other readers. What am I doing wrong? TIA.

    #360963
    gw1500se
    Participant

    I finally got it working if anyone is interested. I had to install another mail reader because Apple mail would not let me see either the error or the message. 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 ‘content-type’ 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!

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Comments are closed