attach file with HTML Mime Mail class

This is a discussion on attach file with HTML Mime Mail class within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi. I'm using HTML Mime Mail class to send emails, but I have a problem trying to attach a ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-21-2003
wakam
 
Posts: n/a
Default attach file with HTML Mime Mail class

Hi. I'm using HTML Mime Mail class to send emails, but I have a problem
trying to attach a local file to the email. I do this:

$attachment = $mail->get_file('example.zip');
$mail->add_attachment($attachment, 'example.zip');

but it looks like it doesn't find the file. I guess that happens
because it tries to find it in the server and it is not there (it's in my
computer).
What can I do and how?
I'm a newbie, so don't be hard with me :-)
Thanks.





Reply With Quote
  #2 (permalink)  
Old 07-21-2003
stephan beal
 
Posts: n/a
Default Re: attach file with HTML Mime Mail class

wakam wrote:
> $attachment = $mail->get_file('example.zip');
> $mail->add_attachment($attachment, 'example.zip');
>
> but it looks like it doesn't find the file. I guess that happens
> because it tries to find it in the server and it is not there (it's in my
> computer).


That code only looks in the directory in which the script is running, which
could be about ANYWHERE (and is not necessarily the directory where the
script lives).

$mail->get_file( dirname(__FILE__)."/example.zip" );

This will work only if the script and the zip file are in the same dir, but
works regardless of where the script is run FROM (which may be much
different than where it lives).

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

Reply With Quote
  #3 (permalink)  
Old 07-21-2003
wakam
 
Posts: n/a
Default Re: attach file with HTML Mime Mail class

"stephan beal" wrote:
> wakam wrote:
> > $attachment = $mail->get_file('example.zip');
> > $mail->add_attachment($attachment, 'example.zip');
> >
> > but it looks like it doesn't find the file. I guess that happens
> > because it tries to find it in the server and it is not there (it's in

my
> > computer).

>
> That code only looks in the directory in which the script is running,

which
> could be about ANYWHERE (and is not necessarily the directory where the
> script lives).
>
> $mail->get_file( dirname(__FILE__)."/example.zip" );
>
> This will work only if the script and the zip file are in the same dir,

but
> works regardless of where the script is run FROM (which may be much
> different than where it lives).
>


I'm not sure if I understand you.
The script will run in the server but the file I want to attach is in my
computer, not on the server.




Reply With Quote
  #4 (permalink)  
Old 07-21-2003
stephan beal
 
Posts: n/a
Default Re: attach file with HTML Mime Mail class

wakam wrote:
> I'm not sure if I understand you.
> The script will run in the server but the file I want to attach is in my
> computer, not on the server.


You can't accomplish that with PHP. No offense intended, but i highly
recommend reading page 1 of the PHP docs before attempting to write PHP
code: PHP is a server-side language, which means that the script will run
only on the server, and has no special knowledge of your client machine.
Thus, any code which you run in your PHP script is executed in the context
of the server, and does not know about the file(s) on your client machine.

Ponder a moment about the possible ramifications if it worked the way you're
trying to make it work: any server could grab any files from any unwitting
web user's machine (provided that client-side security could be bypassed).

You can make an HTML form to upload a file to the PHP-capable server, and
this is covered in the PHP docs:

http://www.php.net/manual/en/features.file-upload.php

but the HTML form you use to do this has nothing at all to do with the
server except that the form's ACTION field must point to the server. In
fact, the form will need to be completely free of PHP unless you run it on
a local web server (in which case your web server can become the client to
the remote web server).

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

Reply With Quote
  #5 (permalink)  
Old 07-21-2003
wakam
 
Posts: n/a
Default Re: attach file with HTML Mime Mail class

stephan beal en un poco habitual momento de lucidez escribió:
> wakam wrote:
>> I'm not sure if I understand you.
>> The script will run in the server but the file I want to attach is
>> in my computer, not on the server.

>
> You can't accomplish that with PHP. No offense intended, but i highly
> recommend reading page 1 of the PHP docs before attempting to write
> PHP code: PHP is a server-side language, which means that the script
> will run only on the server, and has no special knowledge of your
> client machine. Thus, any code which you run in your PHP script is
> executed in the context of the server, and does not know about the
> file(s) on your client machine.
>


I know PHP is server side language, but I thought somehow this was done with
PHP. I didn't know that uploading files was done with pure HTML. How do you
do it?
Thanks a lot.




Reply With Quote
  #6 (permalink)  
Old 07-21-2003
s a n j a y
 
Posts: n/a
Default Re: attach file with HTML Mime Mail class

HTML form to upload a file :

<form action="upload.php" method="post" ENCTYPE="multipart/form-data">
Upload Image : <input type="file" size="60" name="fileName">
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
<input type="submit" value="upload">
</form>


PHP to copy the file :

<?
copy($fileName, "/your Directory/$fileName_name");
?>


"wakam" <escribanoNOSPAM@euskalnet.net> wrote in message
news:bfhl12$ecbem$1@ID-75853.news.uni-berlin.de...
> s a n j a y en un poco habitual momento de lucidez escribió:
> > you can first upload the file using a HTML form (like you do on
> > hotmail or yahoo mail), store it in some directory on your server.
> > Feed this directory name and filename to the send mail script. that
> > should work.
> >

>
> I know this question has no relation with php but, how can you do that

html
> form?
> Thank you.
>
>
>
>



Reply With Quote
  #7 (permalink)  
Old 07-22-2003
stephan beal
 
Posts: n/a
Default Re: attach file with HTML Mime Mail class

wakam wrote:
> with PHP. I didn't know that uploading files was done with pure HTML. How
> do you do it?


i'll repeat from the last post:

You can make an HTML form to upload a file to the PHP-capable server, and
this is covered in the PHP docs:

http://www.php.net/manual/en/features.file-upload.php

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:12 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0