Sending emails based on templates and placeholders with attachments using php and smtp

Being a web developer I often need to send emails based on user requirements, some time these are simple emails but some times users want to take control of email contents and attachments.

To make it easier for me and other developers I have created a mail library which can be easily switched to php native mail() function or smtp backend.

For smtp it is using swiftmailer and phpmailer, you can configure any of these as your smtp backend, by default swiftmailer is enabled as default smtp sender.

How to use library

Please download the library from gitub at following location

you can git clone or download to your project directory

create mail sender script


require_once 'Tecnotch/bootstrap.php';
use Tecnotch;

$mailer = TecnotchFactory::mailer('simple');
//keep them in order as they are below
$placeholders = array(
    "[user_name]" => "John Doe"
    ->setTemplatePath(__DIR__ . '/html/email/en')
    ->setTo(array("" => "Tofeeq Rehman", "" => "Tof33q"))
    ->setCc(array("" => "Tofeeq Testing", "" => "Dev Tofeeq"))
    ->setFrom(array("" => "Tecnotch"))
    ->setReplyTo(array("" => "Tecnotch-Suport"))
    ->addAttachment(__DIR__ . '/test1.pdf', 'Test PDF 1', 'pdf')
    ->addAttachment(__DIR__ . '/test2.pdf', 'Test PDF 2', 'pdf')
    ->addAttachment(__DIR__ . '/test3.pdf', 'Test PDF 3', 'pdf')

You can read further examples and documentation on Github page

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s