August 2, 2010

php: send email when ftp-upload was a success?

Question by matt

hey guys,
i wonder what i’m doing wrong? I’m working on a ftp-upload with php. if files are uploaded successfully i want to get a confirmation email. just a simple email.

if my connection to the FTP Server was a success i’m calling the sendmail() function! it’s not working!

        function sendmail() {
            $EmailFrom = "do-not-reply@mypage.com";
            $EmailTo = "myemail@mypage.com";
            $Subject = "File uploaded to your FTP Server";
            $Body = "Howdy, files have just been transferred to your Server.";
            // Email Headers with UTF-8 encoding
            $email_header = "From: " . $EmailFrom . "rn";
            $email_header .= "Content-Type: text/plain; charset=UTF-8rn";
            $email_header .= "Reply-To: " . $EmailFrom . " rn";
            $success = mail($EmailTo, $Subject, $Body, $email_header);
            if ($success){
              print "success with EMAIL";
            }
            else{
              print "error with EMAIL";
            }
        }

any idea what i’m doing wrong here? does the $EmailFrom value have to be an actual Emailaddress? It’s just not working. Neither success nor error gets printed out. And nothing of my code AFTER the function-call gets executed.

thank you for your help

Answer by Starx

Well if you want to sendmail() when ftp upload is success do something like this

$status = move_uploaded_file($src,$destination);
if($status) { sendmail(); }

What this will do this, first $status will hold the boolean value whether the upload is successful, and if it suceeds then it will call your sendmail() function

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!