FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Email attachment 0bytes using php4
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Email attachment 0bytes using php4 [message #182580] Fri, 16 August 2013 19:09 Go to next message
Dave Drekter is currently offline  Dave Drekter
Messages: 2
Registered: August 2013
Karma: 0
Junior Member
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;
$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?
Re: Email attachment 0bytes using php4 [message #182581 is a reply to message #182580] Fri, 16 August 2013 19:26 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 16-08-2013 21:09, 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;


$file now contains'/tmp2tmporder2'

>
> Any ideas why the attached file is blank?
>

yes, it cannot find your file, because it's not at the location you
specified ;)
Re: Email attachment 0bytes using php4 [message #182582 is a reply to message #182580] Fri, 16 August 2013 19:32 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)powerfulhosting(dot)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(at)attglobal(dot)net
==================
Re: Email attachment 0bytes using php4 [message #182583 is a reply to message #182581] Fri, 16 August 2013 19:37 Go to previous messageGo to next message
Dave Drekter is currently offline  Dave Drekter
Messages: 2
Registered: August 2013
Karma: 0
Junior Member
Luuk: That was it! I owe you. I do a lot of marketing/advertising kinda stuff so if you need something rattle my cage. dave(at)powerfulhosting(dot)com Thanks.


On Friday, August 16, 2013 12:26:50 PM UTC-7, Luuk wrote:
> On 16-08-2013 21:09, 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;
>
>
>
>
>
> $file now contains'/tmp2tmporder2'
>
>
>
>>
>
>> Any ideas why the attached file is blank?
>
>>
>
>
>
> yes, it cannot find your file, because it's not at the location you
>
> specified ;)
Re: Email attachment 0bytes using php4 [message #182584 is a reply to message #182580] Fri, 16 August 2013 19:42 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
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
Re: Email attachment 0bytes using php4 [message #182585 is a reply to message #182580] Fri, 16 August 2013 19:57 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
Dave Drekter:

> That said, for many reasons it's not possible to upgrade to php5 and
> use phpMailer - as much as I'd like to.

There are versions of PHPMailer that work under PHP 4:
<http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php4/>.

However, you may reconsider the reasons for not upgrading to PHP 5. The
last maintainence relase of PHP 4 is already 5 years old--a lot of bugs
and vulnerabilities have been fixed since then.

--
Christoph M. Becker
Re: Email attachment 0bytes using php4 [message #182586 is a reply to message #182580] Fri, 16 August 2013 20:50 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 16/08/13 20:09, 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
>

TYhis worked for me. obviusly its not your finalsolution

function mail_html_file($email, $subject,$from,$return_path,$body)
{

$attach=
chunk_split(base64_encode(file_get_contents('../Images/Logo2.gif')));
$boundary = md5( time() );

$headers = sprintf("From: %s\nMIME-Version: 1.0\nContent-Type:
multipart/related; boundary=\"%s\"",
$from, $boundary);

$message = sprintf("--%s\nContent-Type: text/html;
charset=\"iso-9959-1\"\nContent-Transfer-Encoding:
quoted-printable\n\n%s\n\n--%s\nContent-Type: Image/gif;
name=\"Logo.gif\"\nContent-ID: <Logo2.gif>\nContent-Transfer-Encoding:
base64\n\n%s\n\n--%s--\n",
$boundary,$body,$boundary,$attach,$boundary);
mail($email, $subject, $message, $headers, "-f ".$return_path );
}
That worked on a linux apache exim mail based system..

--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Limiting # characters in textarea
Next Topic: Function Problem
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 10:52:47 GMT 2024

Total time taken to generate the page: 0.02333 seconds