Jump to content

Creating mail() with text/plain, text/html and attachments


JakeTheSnake3.0

Recommended Posts

I know my mail() script is working because I can receive emails from the server.  The only problems I am having are that my email isn't 'set up' properly...and when I say 'set up', I mean that there's something screwy going on, or I don't understand something that is causing some problems to occur.

 

Let's say I want to make an email which contains plain text as a default, but if the user has HTML enabled then the HTML text will show instead.  Also, in that same email I want to attach 1 or more files.  That is example 1.  In example 2, I want to send the email without any attachments but with both plain text and html text.  The 3rd example is when I would want to send plain text with an attachment.

 

Here is what I have in the email once it is sent by the server...

 

To: 
Subject: Test
From: <[email protected]>
Reply-To: <[email protected]>
X-Sender: <[email protected]>
X-Mailer: PHP/4.4.4
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="PHP-mixed-3953d7db39fdc1ca821af7e1f3dc2a58"
Message-Id: <this_works_so_ingore_it>
Date: Fri, 27 Apr 2007 11:51:15 -0400

This message contains one or more attachments.

--PHP-mixed-3953d7db39fdc1ca821af7e1f3dc2a58
Content-Type: multipart/alternative; boundary="PHP-alt-3953d7db39fdc1ca821af7e1f3dc2a58"

This message contains both plain text and html text.

--PHP-alt-3953d7db39fdc1ca821af7e1f3dc2a58
Content-type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

Plain text...

--PHP-alt-3953d7db39fdc1ca821af7e1f3dc2a58
Content-type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>Website</title>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="http://www.website.com/css/email.css" title="Email CSS" />
</head>

<body>
<h1>OMG</h1>
<p>I can't believe this worked!</p>
</body>
</html>

--PHP-alt-3953d7db39fdc1ca821af7e1f3dc2a58
Content-Type: image/jpeg; name="grand_opening.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="grand_opening.jpg"
Content-Location: grand_opening.jpg

[ATTACHMENT CONTENT]

--PHP-mixed-3953d7db39fdc1ca821af7e1f3dc2a58--

 

Am I doing something wrong with the above code?  Can anyone suggest anything?  Also something of note...in Thunderbird, the attachment arrives just fine...but it also appears in the body...probably just a feature.  But in Outlook 2003, the attachment doesn't even get recognized...it gets downloaded, but it doesn't allow me to open/save.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.