MIME Email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nigel-9SW
Forum Newbie
Posts: 8
Joined: Tue Oct 15, 2002 2:14 am
Location: UK

MIME Email

Post by nigel-9SW »

I have read a lot, and I mean a lot of details about MIME email but all the examples appear to be very complex. Is there a simple method to take an HTML page and send it as part of an email ?
Cheers one and all
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

MAIL()
User avatar
nigel-9SW
Forum Newbie
Posts: 8
Joined: Tue Oct 15, 2002 2:14 am
Location: UK

Post by nigel-9SW »

Thanks for the help but.....

What I need to know is the header settings and how to deal with multipart and boundaries etc.

Any help on this would be useful

Cheers
skyhawk133
Forum Newbie
Posts: 9
Joined: Wed Nov 13, 2002 10:25 pm
Location: Rio Rancho, NM

Post by skyhawk133 »

Don't know if you've seen this one yet:

Code: Select all

$headers = "From: dream.in.code <forums@dreamincode.net>\r\n"; 
$headers .= "To: ".$name."<".$email.">\r\n"; 

//specify MIME version 1.0 
$headers .= "MIME-Version: 1.0\r\n";  

//unique boundary 
$boundary = uniqid("HTMLDEMO");  

//tell e-mail client this e-mail contains//alternate versions 
$headers .= "Content-Type: multipart/alternative" .  
   "; boundary = $boundary\r\n\r\n";  

//message to people with clients who don't 
//understand MIME 
$headers .= "This is a MIME encoded message.\r\n\r\n";  

//plain text version of message 
$headers .= "--$boundary\r\n" .  
   "Content-Type: html/text; charset=ISO-8859-1\r\n" .  
   "Content-Transfer-Encoding: base64\r\n\r\n";  
$headers .= chunk_split(base64_encode("$plain"));  

//HTML version of message 
$headers .= "--$boundary\r\n" .  
   "Content-Type: text/html; charset=ISO-8859-1\r\n" .  
   "Content-Transfer-Encoding: base64\r\n\r\n";  
$headers .= chunk_split(base64_encode("$html"));  


//Finally, last but not least... send the email

mail($email, $subject, "", $headers);
$plain and $html are the 2 variables you pass this script that send a plain text and an HTML email, $email is the email addy of the recipient and $subject is the email subject.

I use this on a weekly basis to send out a newsletter to my 2000+ members and it works great. AOL users are pretty much SOL and anyone without an email proggie that supports MIME headers is also SOL, but hey... what would the world be without AOL users and the other folks?!
User avatar
nigel-9SW
Forum Newbie
Posts: 8
Joined: Tue Oct 15, 2002 2:14 am
Location: UK

Post by nigel-9SW »

Thanks I will try this.

I have been experimenting with htmlMimeMail from phpguru.org

So far I have built some html emails with backgrounds and multiple images (gifs and jpgs) with success.

My next step is to include some sounds files (midi) that also can be sent with the email. Does anyone know how to do this ?

I have attached the files but this results in the email showing an attachment, the midi does not play automatically.
skyhawk133
Forum Newbie
Posts: 9
Joined: Wed Nov 13, 2002 10:25 pm
Location: Rio Rancho, NM

Post by skyhawk133 »

Link it from offsite, full http://www..... address

Here is the newsletter I send out with that script:

http://home.dreamincode.net/newsletters/111102.php
unclep
Forum Newbie
Posts: 3
Joined: Wed Apr 24, 2002 6:53 am

Post by unclep »

I tried to use the script provided, but I'm having some difficulties. When I check the mail on my Hotmailaccount, everything is OK. When I check mail within my own webmailaccount, which only supports plain text, everything is OK as well.
But when I use Outlook the full headers are printed in my message and I don't get the HTMLmessage I created.

Do I need extra headers for Outlook or something like that?
unclep
Forum Newbie
Posts: 3
Joined: Wed Apr 24, 2002 6:53 am

Problem solved

Post by unclep »

I solved the problem myself by deleting \r from the script.
User avatar
nigel-9SW
Forum Newbie
Posts: 8
Joined: Tue Oct 15, 2002 2:14 am
Location: UK

Post by nigel-9SW »

Thanks for all the tips.

I have continued to experiment and discovered that the phpguru script works well, excpet the real pain is having to enter all the image refrences from the linked html page.

what I have been seeking is a parsing script to read the linked html, extract all the image links and pass these to the phpguru script before sending email.

The last step is to create a form to handle the selected recipients and the html to send and I will have an automated HTML emailer.

On the sound attachement front I have used a link to the web from within the eamil html, but this does not work ? It does if I open the html directly, but not from within outlook. Any ideas anyone?
Post Reply