You are here: Mail With Attachment Problem « PHP Language « IT news, forums, messages
Mail With Attachment Problem

Posted by Tim McGurk on 12/13/06 16:30

I'm trying to send an e-mail with an attachment to Send2Fax, which is a
service that takes an e-mail with an attachment and sends it to a designated
fax number

The code I have works fine if I'm sending the attachment to a mailbox, but
when sending to Send2Fax what ends up happening is the attachment is
apparently being read in as a text file, and instead of, say, a .jpg being
faxed the output is 7 or 8 pages of gibberish. Send2Fax provides code, but
not for sending an attachment (and they DO accept attachments- it works fine
from an e-mail client like Outlook)

Here's the code I'm using (found it on the internet). Any help would be
GREATLY appreciated!

function mail_attachment($file,$mailto, $from_mail, $from_name, $replyto,
$subject, $message)
{
$filename=basename($file);
$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($file);
$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: application/octet-stream;
name=\"".$filename."\"\r\n"; // use diff. tyoes here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment;
filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header))
{
return true;
}
else
{
return false;
}
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация