Automated Email Responce - Help Needed Please?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jjfletcher90
Forum Newbie
Posts: 18
Joined: Sat Jul 09, 2011 12:38 pm

Automated Email Responce - Help Needed Please?

Post by jjfletcher90 »

:D Hello,

I need assistance adding the automated email portion of the code to the below php...

I would like to achieve the following with the below upload code... Once the user
selects the upload button, I would like to receive an email that the user
has sent up a file to the server... Is this possible with the below
upload.php file ?

Code: Select all

 
<?php
    header("Location:http://www.website.com/upload.html");
?>
 <?php
 $target = "upload/";
 $target = $target . basename( $_FILES['uploaded']['name']) ;
 $ok=1;
 
 //This is our size condition
 if ($uploaded_size > 350000)
 {
 echo "Your file is too large.<br>";
 $ok=0;
 }
 
 //This is our limit file type condition
 if ($uploaded_type =="text/php")
 {
 echo "No PHP files<br>";
 $ok=0;
 }
 
 //Here we check that $ok was not set to 0 by an error
 if ($ok==0)
 {
 Echo "Sorry your file was not uploaded";
 }
 
 //If everything is ok we try to upload it
 else
 {
 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
 {
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been
uploaded";
 }
 else
 {
 echo "Sorry, there was a problem uploading your file.";
 }
 }
 
 ?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Automated Email Responce

Post by social_experiment »

Code: Select all

<?php
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
 {
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been
uploaded";
 @mail($to, $subject, $msg, $headers);
 }
?>
This should send a message if the file has been uploaded
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
jjfletcher90
Forum Newbie
Posts: 18
Joined: Sat Jul 09, 2011 12:38 pm

Re: Automated Email Responce - Help Needed Please?

Post by jjfletcher90 »

where do I put my email address in the below code and where in the upload.php do I put your solution?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Automated Email Responce - Help Needed Please?

Post by social_experiment »

Code: Select all

<?php
 //
 $to = 'your@mail.addy';
 $subject = 'Your subject';
 $msg = 'A file was uploaded';
 $headers = 'From: noreply@yoursite';
 //
@mail($to, $subject, $msg, $headers);
?>
jjfletcher90 wrote:where in the upload.php do I put your solution?
Right after the file has been uploaded, where i added it
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply