I'm trying to make a multipart mime mail with the imap_mail_compose function but U think I must be missing something as it aint working.

Specifically - I've got multipart/mixed and multipart/alternative mails to work but I can't work out how to generate a multipart/mixed mail that also contains a multipart/alternative part - no error messages either as it just crashes PHP.

Here's my code:

<?php

$mimeTypes=Array ('TEXT','MULTIPART','MESSAGE','APPLICATION','AUDIO','IMAGE','VIDEO','OTHER');
$attachments[]=Array(filename=>"myimage.gif",mime=>"IMAGE/gif",data=>"This isn't really an image 🙂");
$attachments[]=Array(filename=>"myimage2.gif",mime=>"IMAGE/gif",data=>"This isn't really an image 🙂");

$pageText="This is a test message!<BR><B><P ALIGN=\"CENTER\">E=MC<SUP>2</SUP></P></B><HR>";

$sendStyle="plain";
$part="";

$text=eregi_replace("<P([:space:]?[>]{1,})","\r\n\r\n<!--REMOVE--",$pageText);
$text=eregi_replace("<BR>","\r\n",$text);
$text=eregi_replace("<HR>","\r\n".str_repeat("-",74)."\r\n",$text);
$text=eregi_replace("<!--REMOVE-->","",$text);

$part[]=Array(
type => TYPETEXT,
subtype => "plain",
encoding => ENCQUOTEDPRINTABLE,
'contents.data' => imap_8bit(strip_tags($text))
);

if ($sendStyle=="html")
{
$htmlHeading="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\r\n";
$htmlHeading.="\r\n";
$htmlHeading.="<HEAD>\r\n";
$htmlHeading.="<META NAME=\"GENERATOR\" CONTENT=\"$server[mailerVersion]\">\r\n";
$htmlHeading.="</HEAD>\r\n";
$htmlHeading.="<BODY>\r\n";

array_unshift($part,Array(type=>TYPEMULTIPART,subtype=> "alternative"));

$part[]=Array(
				type 			=>	TYPETEXT,
				subtype			=>	"html",
				encoding		=>	ENCQUOTEDPRINTABLE,
				'contents.data'	=>	imap_8bit($htmlHeading.$pageText)
			);

}

if (count($attachments))
{
array_unshift($part,Array(type=>TYPEMULTIPART,subtype=> "mixed"));

while (list($key,$value) = @each($attachments))
{
	$mime=explode("/",$value[mime]);
	$type=array_search(strtoupper($mime[0]),$mimeTypes);

	$part[]=Array(
					type 			=> 	$type,
					subtype			=>	$mime[1].";\n\tname=\"$value[filename]\"",
					encoding		=>	ENCBINARY,
					'contents.data'	=>	imap_binary($value[data])
				);
}

}

var_dump($part);

$message=imap_mail_compose(array(),$part);

echo $message;

$message=explode("\r\n\r\n",$message);
$headers=str_replace("BOUNDARY=","\n\tBOUNDARY=",array_shift($message)."\n");
$headers.="X-Mailer: OoAr Mailer V0.78\n";
$headers.="X-Priority: 3\n";
$headers.="Return-Path: danny@linux.localdomain\n";
$message=implode("\r\n\r\n",$message);

imap_mail("Danny Shepherd <danny@linux.localdomain>","Test Subject",$message,$headers,"","","Danny Shepherd <danny@linux.localdomain>");

?>

The PHP manual is absolutly no help either.

    Write a Reply...