user2432677
user2432677

Reputation: 75

Why wont this email me a notification

Hi I've just got this video uploader form up and running and it works just fine. However I want some sort of notification to my email to let me know that someone has just uplaoded a video to my server. But it isn't notifying me I have totally simplified it just to get some sort of message to me but its just not functioning what have I missed?`

if(isset($_FILES["FileInput"]) && $_FILES["FileInput"]["error"]== UPLOAD_ERR_OK)
{

$UploadDirectory    = '../video_uploader/uploads/';


if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
    die();
}


//Is file size is less than allowed size.
if ($_FILES["FileInput"]["size"] > 500242880) {
    die("File size is too big!");
}

//allowed file type Server side check
switch(strtolower($_FILES['FileInput']['type']))
    {
        //allowed file types
        case 'image/png': 
        case 'image/gif': 
        case 'image/jpeg': 
        case 'image/pjpeg':
        case 'text/plain':
        case 'text/html': //html file
        case 'application/x-zip-compressed':
        case 'application/pdf':
        case 'application/msword':
        case 'application/vnd.ms-excel':
        case 'video/mp4':
            break;
        default:
            die('Unsupported File!'); //output error
}

$File_Name          = strtolower($_FILES['FileInput']['name']);
$File_Ext           = substr($File_Name, strrpos($File_Name, '.')); 
$Random_Number      = rand(0, 9999999999); //Random number to be added to name.
$NewFileName        = $Random_Number.$File_Ext; //new file name

if(move_uploaded_file($_FILES['FileInput']['tmp_name'], $UploadDirectory.$NewFileName   ))
   {
    die('Success! File Uploaded.');
}else{
    die('error uploading File!');
}

}
else
{
die('Something wrong with upload! Is "upload_max_filesize" set correctly?');
}


mail("[email protected].", $NewFileName);





?>`

Upvotes: 0

Views: 57

Answers (3)

Aksh
Aksh

Reputation: 654

Try this.changes the fields according to your needs.

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "To: [email protected]" . "\r\n";
$headers .= "From: demo.com <[email protected]>" . "\r\n";

mail('[email protected]', $subject, $message, $headers);
// subject and message just choose according to your needs and it should be in html format.

for further reference follow these links

http://www.w3schools.com/php/php_ref_mail.asp
http://php.net/manual/en/function.mail.php

Upvotes: 2

Patrick Falize
Patrick Falize

Reputation: 599

That is not how php mailer works. It needs headers, a subject and a message. Without the proper headers the email won't send because it doesn't know were to go. Also, when you have everything setup: "check your spambox"

http://www.w3schools.com/php/php_ref_mail.asp

http://php.net/manual/en/function.mail.php

Upvotes: 1

andrew
andrew

Reputation: 2098

Check your code again in this section:

if(move_uploaded_file($_FILES['FileInput']['tmp_name'], $UploadDirectory.$NewFileName   ))    
{
        die('Success! File Uploaded.'); 
}
else
{
        die('error uploading File!'); 
}

So, if your file is failed to upload, your script dies die() with an error message.
If on the other hand your upload succeeds, your scripts dies die() again.
Is this sounds logical to you? Your script never gets to the point where it should send an email.

Also, mail() function needs 3 parameters, as others have suggested.

Upvotes: 0

Related Questions