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

Email notifications when someone upload a file

Open gfr1991 opened this issue 14 years ago • 6 comments

Hi everyone, I need to implement a function on my code. Need an email notification when someone upload a file on my server. I'm struggling to figure it out but unsuccessfully. Hope you can help me. Bye GF

gfr1991 avatar Jul 17 '12 15:07 gfr1991

hi, gfr1991 you can use "phpmailer class",

in jquery.fileupload-ui.js: search: // Callback for successful uploads: done: func......

and use a ajax to call to send.php this require (phpmailer class).

this class is very easy to configure you can use google to find it.

i hope help you.

jagl007 avatar Jul 17 '12 15:07 jagl007

Very thanks jagl007. But I'm not so good as you expected to, so... Is it a problem if I ask you to explain a little bit more exhaustive (better if step by step :P) how to do this? Especially for the done: function. If you can give me the code I'd be forever grateful :)

gfr1991 avatar Jul 17 '12 16:07 gfr1991

first you can create inputs on index.html

next in jquery.fileupload-ui.js: after completed the uploaded file (done) insert:

var dataString = 'to=' + $(".to").val() + '&from=' + $(".from").val() + '&tomal=' + $(".tomail").val() + '&frommail=' + $(".frommail").val(); $.ajax({ type: "POST", url: "send.php", data: dataString, beforeSend: function(){ $('#msgUser').html('loading'); }, success: function(answer){ $('#msgUser').html(answer); } });

this is a basic call to php with ajax. add in a folder a phpmailar class configure it. with your adreeses.

jagl007 avatar Jul 17 '12 16:07 jagl007

Nope, it doesn't work. Maybe you can help me another time. I've added this code in my jqeury.fileupload-ui.js

done: function (e, data) { var dataString = 'to=' + $(".to").val() + '&from=' + $(".from").val() + '&tomal=' + $(".tomail").val() + '&frommail=' + $(".frommail").val(); $.ajax({ type: "POST", url: "send.php", data: dataString, beforeSend: function(){ $('#msgUser').html('loading'); }, success: function(answer){ $('#msgUser').html(answer);} }); var that = $(this).data('fileupload'), template;

Then in the exactly same folder of jquery.fileupload-ui.js I've added two file: send.php and class.phpmailer.php. Only this two files. I've no edited class.phpmailer.php, simply downloaded from his project-site and place into that folder. This is the code of send.php:

From = "[email protected]"; $mail->FromName = "Nome Mittente"; $mail->AddAddress("[MY MAIL]"); $mail->IsHTML(true); $mail->Subject = ciao; $mail->Body = ciao; $mail->AltBody = $bodytxt; $mail->AddAttachment("public/filename_1.zip"); $mail->AddAttachment("public/filename_2.zip"); if(!$mail->Send()){ echo "Si è verificato un errore nell'invio della mail"; }else{ echo "Mail inviata con successo"; } ?>

Don't know where's wrong, but when I up a file I don't recieve any mail. Please help me :(

gfr1991 avatar Jul 17 '12 19:07 gfr1991

Ok, So I've solved some parts of the problems. Phpmailer and send.php are just ok. Send.php definitevely works if I call it from my browser: it send me the mail. Now the question is: how to call this file after a successfull upload? I only need this code :)

gfr1991 avatar Jul 17 '12 20:07 gfr1991

Nobody? :(

gfr1991 avatar Jul 19 '12 10:07 gfr1991