Email notifications when someone upload a file
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
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.
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 :)
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.
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:
require_once("class.phpmailer.php"); $mail = new PHPMailer(); $mail->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 :(
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 :)
Nobody? :(