Re: Email attachment 0bytes using php4 [message #182584 is a reply to message #182580] |
Fri, 16 August 2013 19:42 |
Peter H. Coffin
Messages: 245 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Fri, 16 Aug 2013 12:09:36 -0700 (PDT), Dave Drekter wrote:
> Ok, don't holler at me, I understand php4 is no longer. That said, for many reasons it's not possible to upgrade to php5 and use phpMailer - as much as I'd like to. I've searched around and there's no other answer presented. So, here's the problem. I create a text file /tmp2/tmporder2
>
> The code below sends the email fine with the attachment, but the attachment contains 0 bytes, NADA.
>
> <?php
> $path = '/tmp2';
> $filename = 'tmporder2';
> $mailto = 'dave(at)powerfulhosting(dot)com';
> $from_mail = 'estore order receipt';
> $from_name = 'bagelworks order';
> $replyto = '';
> $subject = 'TESTING EMAIL ATTACHMENT';
>
> $file = $path.$filename;
No slash here? What's in '/tmp2tmporder2'?
> $file_size = filesize($file);
> $handle = fopen($file, "r");
> $content = fread($handle, $file_size);
> fclose($handle);
> $message=$handle;
What's this supposed to do? It looks like you're trying to put the same
text file into the text plain part *and* as a base64 encoded version of
the same thing. Maybe you are, but that just seems like a fantastic way
to add a lot of obscure redundancy.
>
> $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 different content types 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)) {
> echo "mail send ... OK"; // or use booleans here
> } else {
> echo "mail send ... ERROR!";
> }
> ?>
>
> Any ideas why the attached file is blank?
--
Remember, a 12'x12'x18" raised floor can hold over a thousand gallons of
blood before it starts to seep up through the cracks.
-- Roger Burton West in the Monastery
|
|
|