How to mail uploaded file

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
umapathy
Forum Newbie
Posts: 14
Joined: Fri Jul 28, 2006 2:21 am
Location: chennai - india

How to mail uploaded file

Post by umapathy »

Dear Friends

I have one doubt in sending uploaded file to mail.
how can i send mail with uploaded file.?
If any one known please post with coding


Thanks and Regards

Umapathy
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I would recommend using a email class like SwiftMailer or phpMailer to create the email with an attachment. Either of these libraries will make it easy for you.
(#10850)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Wihtout any error checking/sanitization this is how you'd do it with Swift. I should probably use a file upload example in my documentation actually.... I'm going to open the documentation to take user comments which will help.

Code: Select all

if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comment']))
{
    //Turn her on
    $swift = new Swift(new Swift_Connection_SMTP('smtp.yourhost.tld'));
    //Add the message
    $swift->addPart($_POST['comment']);
    //If a file was uploaded, attach it
    if (!empty($_FILES['uploadname']['tmp_name']) && !$_FILES['uploadname']['error']))
    {
        $swift->attachFile(
          file_get_contents($_FILES['uploadname']['tmp_name']),
          $_FILES['uploadname']['name'],
          $_FILES['uploadname']['type']);
    }
    //Then send the email
    if ($swift->send('your@address', $_POST['email'], 'Subject')) echo "Mail Sent";
    else echo "Mail not sent";
    
    $swift->close();
}
jito
Forum Commoner
Posts: 85
Joined: Sat Mar 25, 2006 4:32 am
Location: india

Post by jito »

search google for " php mail with attachment". you will find tons of free code. You can also use mailer classes.
Post Reply