Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Samuel Mamulaschwili
9,935 PointsRun php script after form submisson
Hey guys,
I`ve finished some php tracks and try to code my own project. Right now I submit a simple form to mysql database and store the entries there. Next I want to create a pdf file (with fpdf: www.fpdf.org). I wrote the script that generate the pdf from the databse entries.
I have no idea how the send this pdf file as an email attachment automatically after the database storage. Whats the best way to "trigger" this after I hit the "send" button?
Thanks for helping me out
Sam
1 Answer

Shawn Gregory
Courses Plus Student 40,672 PointsHello,
Just use the PHPMailer addon to add your attachments. It has the ability to add attachments to your emails that you are sending via the mail() function. Take a look at the following example I got from StackOverflow:
<?php
$email = new PHPMailer();
$email->From = 'you@example.com';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( 'destinationaddress@example.com' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();
?>
Hope this points you in the right direction.
Cheers!
(Citation: http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail , Stack Overflow)