jQuery-File-Upload icon indicating copy to clipboard operation
jQuery-File-Upload copied to clipboard

Sending automatic email after an upload

Open gfr1991 opened this issue 14 years ago • 12 comments

Hi there; I was struggling to make jquery file upload send me an email after someone upload a file. Guess you can help me in figure it out. I've setted up a php file that, if invoked, send me the mail I want but I don't know how to get it from the jquery file upload script. Hope you can help me. Ask me if you need further information. Please!

gfr1991 avatar Aug 25 '12 16:08 gfr1991

Put the code to send the email in server/php/upload.class.php

d3xtro avatar Aug 27 '12 07:08 d3xtro

Great, it works! But now I have an additional problem: when I upload a file the system returns me this error: "SyntaxError: JSON.parse: unexpected character". I know it depends on the PHP code I've inserted, but I don't know why and how to solve it. Can you help me again? Here's the code I've inserted: $mail = new PHPMailer();

$mail->From = "upload@email"; $mail->FromName = "name"; $mail->AddAddress("myemail@email"); $mail->IsHTML(true);

$mail->Subject = "{$context[user][name]} ,.."; $mail->Body = "Part of the message
{$context[user][name]}Another part of the message
another part between brtag
"; $mail->WordWrap = 50;

if(!$mail->Send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; }

gfr1991 avatar Aug 27 '12 19:08 gfr1991

The code looks fine it must be where you inserted it that is causing the problem. Paste the entire file after you've inserted the code https://gist.github.com/

d3xtro avatar Aug 27 '12 19:08 d3xtro

Firstly, let me thank you for your patient help. Here's the whole code: https://gist.github.com/7b04be7898e098c1c9db . Actually I didn't know where to insert the code...

gfr1991 avatar Aug 27 '12 19:08 gfr1991

Try something like https://gist.github.com/2cbf8d2c668e6f0441f1

d3xtro avatar Aug 27 '12 20:08 d3xtro

Nope, this way I don't even receive the mail. Guess the function sendmail() doesn't work properly. I have also tried with the strict syntax of that function ( function sendmail($to... etc.) ) but still didn't work. Is there a way to make only run the code I posted above within a function? E.g. a "function run()"...?

gfr1991 avatar Aug 27 '12 20:08 gfr1991

Ok, I reach my goal. I put the code in the index.php file which is in the same folder of upload.class.php and it works. Then I have my last question. How do I retrieve the filename of the uploaded file? I tried with $file_name but it didn't work. Meanwhile thank you for everything in advance and for what you'll eventually do in advance.

gfr1991 avatar Aug 27 '12 23:08 gfr1991

add print_r($_FILES, true) to the email body to get a output of file info

d3xtro avatar Aug 28 '12 02:08 d3xtro

It works, but returns me a list of arrays. Not very intelligible. Is there a way to display only the filename? :)

gfr1991 avatar Aug 28 '12 10:08 gfr1991

foreach ($_FILES as $f)
    $body .= $f['name'] . "<br>";

d3xtro avatar Aug 28 '12 15:08 d3xtro

You're great. This foreach ($_FILES as $f) $body .= $f['name']['0'] . "
"; works. Fantastic. Let me thank you another time :)

gfr1991 avatar Aug 28 '12 15:08 gfr1991

Dear All,

I have the same problem.but it very complex for me to understand this because there is modified file but after that there is several posts.so plase can you explain it bit more.this is really urgent.

Thanks

dumindard avatar Sep 09 '12 06:09 dumindard