I am coming from a .net/C# background and we have recently moved to a Craft/Twig platform. What is the best way to do this: Have a visitor come to a Craft webpage (Twig file), enter their email address in a text box, hit a button, and have an email message sent to them containing a PDF attachment that they selected from that page?

Is this functionality built-in to Craft or do I need a plugin?

1 Answer 1


You can do this with a simple Craft plugin. You can generate the boilerplate plugin code here.

Your form on the front-end will set its hidden action input to your plugin's controller's action.

From there, you can use Craft's EmailModel (along with addAttachment()) and EmailService's sendEmail() to send whatever email contents you wish.

  • I just spent a few days going through Mijingo's Craft Plugin Course. So, I can now attack this and see if I can make it work.
    – Chip Shank
    Apr 19, 2017 at 22:05
  • Does addAttachment work ok on local host urls? I have the following: $pubpath = /localhost:3000/uploads/pubfiles/Lampen2014.pdf ................. $email->addAttachment($pubpath); ................ Email error: Could not access file: //localhost:3000/uploads/pubfiles/Lampen2014.pdf
    – Chip Shank
    Apr 23, 2017 at 14:39
  • As I typed I realized I needed to remove the localhost from the path to /uploads..... etc... and it works fine. Now I just need to remove the first part, is there a quick truncate left method or something like that? Thanks!
    – Chip Shank
    Apr 23, 2017 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.