Sending multipart/alternative html emails w/ attachments

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

Locked
clem_c_rock
Forum Commoner
Posts: 46
Joined: Mon Jun 07, 2004 9:18 am

Sending multipart/alternative html emails w/ attachments

Post by clem_c_rock »

Hello,
Is is possible to send a multipart/alternative html mail w/ attachments at the same time?

Here's some of the headings I have used w/ attacments:

Code: Select all

#---------- #2 ----------------------------------
$message = "<html><body bgcolor=red>
<table width=200 bgcolor=red>
<tr><td>This is the <b>HTML portion</b> of the mixed message.</td></tr>
</table></body></html>";
 
$headers = "From:". $_POST['from'] . "\n";
$headers .= "Bcc:" . $bcc . "\n";
$headers .= "CC: clemrock@hotmail.com";
 
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
 
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed; type=multipart/alternative; \n" .
" boundary=\"{$mime_boundary}\"";
 
//---- send plain text -------
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "This is the plain version";
//----------------------------
 
//---- start message ---------
$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
 
 
if(is_uploaded_file( $file_attachment ) )
{
$file = fopen($file_attachment,'rb');
$data = fread($file,filesize($file_attachment));
fclose($file);
$data = chunk_split(base64_encode($data));
 
$message .= "--{$mime_boundary}\n" ;
$message .= "Content-Type: {$file_attachment_type};\n";
$message .= " name=\"{$file_attachment_name}\"\n";
$message .= "Content-Disposition: attachment;\n";
$message .= " filename=\"{$file_attachment_name}\"\n";
$message .= "Content-Transfer-Encoding: base64\n\n";
$message .= $data . "\n\n";
$message .= "--{$mime_boundary}--\n";
 
echo "<br>duh";
}
 
#----------------------------------------------------
 
 
#########################################
if( $_REQUEST['action_mail'] )
{
if (mail($to, $subject, $message, $headers) )
{
$confirm = "Message Sent!";
}
else{ $confirm = "Failed to send message."; }

}
#########################################

This seems to work but when I view it in Eudora, it shows the html code litterally.

Any ideas?

Clem C
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

This is an exact copy of your last thread. :?

LOCKED
Locked