Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #10535
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Email attachment 0bytes using php4 |
| Date | 2013-08-16 15:32 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <kulup7$311$1@dont-email.me> (permalink) |
| References | <53041805-d7cb-4c72-bec7-c965cd8d1074@googlegroups.com> |
On 8/16/2013 3:09 PM, 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@powerfulhosting.com';
> $from_mail = 'estore order receipt';
> $from_name = 'bagelworks order';
> $replyto = '';
> $subject = 'TESTING EMAIL ATTACHMENT';
>
> $file = $path.$filename;
> $file_size = filesize($file);
> $handle = fopen($file, "r");
> $content = fread($handle, $file_size);
> fclose($handle);
> $message=$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 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?
>
Without trying your code, I can only guess. However, a couple of questions:
1. Why are you trying to put your content in the header? That should go
in the body.
2. Why are you using \r\n\r\n multiple times in your header? This will
insert a blank line, which identifies the beginning of the data.
3. Have you tried looking at the source of the email when it's received,
and compared it to a working attachment, i.e. from thunderbird? This is
the easiest way to see what's not correct.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Email attachment 0bytes using php4 Dave Drekter <powerfulhosting@gmail.com> - 2013-08-16 12:09 -0700
Re: Email attachment 0bytes using php4 Luuk <luuk@invalid.lan> - 2013-08-16 21:26 +0200
Re: Email attachment 0bytes using php4 Dave Drekter <powerfulhosting@gmail.com> - 2013-08-16 12:37 -0700
Re: Email attachment 0bytes using php4 Jerry Stuckle <jstucklex@attglobal.net> - 2013-08-16 15:32 -0400
Re: Email attachment 0bytes using php4 "Peter H. Coffin" <hellsop@ninehells.com> - 2013-08-16 14:42 -0500
Re: Email attachment 0bytes using php4 Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-16 21:57 +0200
Re: Email attachment 0bytes using php4 The Natural Philosopher <tnp@invalid.invalid> - 2013-08-16 21:50 +0100
csiph-web