attach file to email ..

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
stu77
Forum Newbie
Posts: 1
Joined: Mon Oct 12, 2009 7:08 am

attach file to email ..

Post by stu77 »

Hey guys,

I've just started using swift mailer and it's been a good experience so far .. What i'm trying to do is attach a file (be it pdf, image or video under 2mb) to an email message through a form. As I said the form is very basic see what i've got below;

$transport = Swift_MailTransport::newInstance();
//$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)->setUsername('your username')->setPassword('your password');

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance();
$message->setContentType("text/html");
$message->setSubject('order submission');
$message->setFrom('me@emailaddress.com', 'person');
$message->setTo( $_POST['email'] );
$message->setBody('Thank you for submitting your query.');

$result = $mailer->batchSend($message);


If someone could help me out with how to go about this I'd be very greatful.

Cheers ..
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: attach file to email ..

Post by markusn00b »

Check out the documentation on Sending attachments.
Post Reply