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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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. |
|
|||
|
"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. |
|
|||
|
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. |
|
|||
|
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. |
|
|||
|
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. > > > > |
|
|||
|
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. |