Re: Email with attachments coming through damaged
| From: | Justin Patrin | Date: | Wed, 24 Mar 2004 21:41:34 +0000 |
| Subject: | Re: Email with attachments coming through damaged | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-23261@lists.php.net to get a copy of this message | ||
Ron Herhuth wrote:
Hi, I'm trying to send an attachment via email using the following function, but it keeps coming through damaged. I am having no trouble emailing the same attachment using OutLook. Is there something wrong with the function I'm using? The attachment shows up and I'm not getting any errors, but it just won't open up in Acrobat. Thanks, Ron <? $email_address = "ron@tatumcfo.com"; $email_from = "cio.tax@tatumcio.com"; $subject = "Testing Email with attachments"; $msg = "Text message shown in email"; $attach_filepath = array("2003_CIO_K1_Memo.pdf"); xmail($email_address,$email_from,$subject,$msg,$attach_filepath); function xmail($email_address,$email_from,$subject,$msg,$attach_filepath) {I would suggest using a known good solution, such as PEAR's Mail_MIME package. http://pear.php.net/package/Mail_MIME -- paperCrane <Justin Patrin>$b = 0; $mail_attached = ""; $boundary = md5(uniqid(time(),1))."_xmail"; if (count($attach_filepath)>0) { for ($a=0;$a<count($attach_filepath);$a++) { if ($fp = fopen($attach_filepath[$a],"rb")) { $file_name = basename($attach_filepath[$a]); $content[$b] = fread($fp,filesize($attach_filepath[$a])); $mail_attached .= "--".$boundary."\r\n" ."Content-Type: application/pdf; name=\"$file_name\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-Disposition: attachment; filename=\"$file_name\"\r\n\r\n" .chunk_split(base64_encode($content[$b]))."\r\n"; $b++; fclose($fp); } else { echo "NEIN"; } } $mail_attached .= "--".$boundary." \r\n"; $add_header ="MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"$boundary\""; $mail_content = "--".$boundary."\r\n" . "Content-Type: text/plain; charset=iso-8859-1; format=flowed\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n" . $msg."\r\n\r\n".$mail_attached;return mail($email_address,$subject,$mail_content,"From:".$email_from."\r\n".$add_header);} elsereturn mail($email_address,$subject,$msg,"From: ".$email_from); }} ?>