Page 1 of 1
How to mail uploaded file
Posted: Wed Aug 23, 2006 2:11 am
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
Posted: Wed Aug 23, 2006 2:42 am
by Oren
Posted: Wed Aug 23, 2006 2:42 am
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.
Posted: Wed Aug 23, 2006 3:12 am
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();
}
Posted: Wed Aug 23, 2006 3:15 am
by jito
search google for " php mail with attachment". you will find tons of free code. You can also use mailer classes.