|
Posted by Ric on 12/13/06 18:44
Tim McGurk schrieb:
> 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";
Mail standard is only "\r", some email clients don't care if you send
\r\n but lots of providers and apps do and then the mail gets broken.
So remove the \n from all your header tags.
> $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]
|