Re: Create multipart email

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use phpmailer, makes it simple

Bastien

Sent from my iPod

On May 28, 2009, at 4:47, "Guus Ellenkamp" <Ellenkamp_Guus@xxxxxxxxxxx> wrote:

I'm trying to attach an uploaded file to an e-mail which I receive in
Outlook. Neither the first part, nor the second part displays properly. The
header looks ok when displayed on the screen. What am I missing?

See code below.
function xmail($mailto, $from_mail, $from_name, $replyto, $subject,
$message, $origname, $tempfile, $filetype) {

$file = $tempfile;

$file_size = filesize($file);

$handle = fopen($file, "r");

$content = fread($handle, $file_size);

fclose($handle);

$content = chunk_split(base64_encode($content));

$uid = md5(uniqid(time()));

$name = basename($origname);

$header = "From: ".$from_name." <".$from_mail.">\r\n";

$header .= "Reply-To: ".$replyto."\r\n";

$header .= "MIME-Version: 1.0\r\n";

$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n \r\n";

$header .= "This is a multi-part message in MIME format.\r\n";

$header .= "--".$uid."\r\n";

$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";

$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

$header .= $message."\r\n\r\n";

$header .= "--".$uid."\r\n";

$header .= "Content-Type: ".$filetype."; name=\"".$name."\"\r\n"; // use
diff. tyoes here

$header .= "Content-Transfer-Encoding: base64\r\n";

$header .= "Content-Disposition: attachment; file=\"".$name."\"\r\n\r \n";

$header .= $content."\r\n\r\n";

$header .= "--".$uid."--";

echo $header;

if (mail($mailto, $subject, "test", $header)) {

echo "mail send ... OK"; // or use booleans here

} else {

echo "mail send ... ERROR!";

}

}

// how to use

$my_name = "Guus";

$my_mail = "guus@xxxxxxxxxxxxxxxxxxx";

$my_replyto = "guus@xxxxxxxxxxxxxxxxxxx";

$my_subject = "This is a mail with attachment.";

$my_message = "Hallo,\r\ndo you like this script? I hope it will
help.\r\n\r\ngr. Olaf";

xmail("guus@xxxxxxxxxxxxxxxxxxx", $my_mail, $my_name, $my_replyto,
$my_subject, $my_message,$fileName, $fileTempName, $fileType);



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux