PHPackages                             cstudios/craft-smtpmailer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. cstudios/craft-smtpmailer

ActiveCraft-plugin[Mail &amp; Notifications](/categories/mail)

cstudios/craft-smtpmailer
=========================

A contact form plugin to send out emails in various ways

v1.0.0(3y ago)02MITPHP

Since Jul 6Pushed 3y agoCompare

[ Source](https://github.com/cstudiossro/craft-smtpmailer)[ Packagist](https://packagist.org/packages/cstudios/craft-smtpmailer)[ RSS](/packages/cstudios-craft-smtpmailer/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (2)Dependencies (3)Versions (2)Used By (0)

[![](https://raw.githubusercontent.com/cstudiossro/craft-smtpmailer/main/src/icon.svg)](https://raw.githubusercontent.com/cstudiossro/craft-smtpmailer/main/src/icon.svg)

SMTP Mailer Plugin for Craft CMS
================================

[](#smtp-mailer-plugin-for-craft-cms)

> We've built this plugin for internal use, but we've decided to make it public

SMTP Mailer provides additional options to send out mails compared to Pixel&amp;Tonic`s Contact Form. However you have to programatically set up everything. There is no Control Panel interface for this plugin.

> Make sure to carefully read the instructions before you use this plugin.

Instructions
------------

[](#instructions)

Add these lines to your `.env` file

```
MAILER_HOST=smtp.example.com
MAILER_USERNAME=login@example.com
MAILER_PASSWORD=********
MAILER_PORT=465
MAILER_ENCRYPTION=ssl
MAILER_DELIVERY_PROTOCOL=smtp
```

Obviously these are just placeholders, you need your own smtp configuration to make this work.

Create a `_mails` directory under your `templates`Notice the underscore &gt; `_`

`templates/_mails`

Create a `email_template_config.php` file inside your config folder &gt; `config/email_template_config.php`and copy the contents of this [file](https://raw.githubusercontent.com/cstudiossro/craft-smtpmailer/main/email_template_config.php)into that

How do these templates work?
----------------------------

[](#how-do-these-templates-work)

`templates/_mails` contains your email templates. These will be sent out to the email addresses. The files inside this directory will get the variables you will set up on the contact pages.

Example:

You have a job application form (e.g. here: `templates/pages/contact.twig`). You might want to get the applicants age

If you use this code:

```
How old are you

```

Then you can use this variable inside your email template (That you might set up here `templates/_mails/job_contact.twig`) like this:

```
Applicant's age: {{ applicant_age }}
```

This is depends on what you've entered into your input field's name attribute. (`name="variable_name"`)

Where will we send the email?
-----------------------------

[](#where-will-we-send-the-email)

First of all, it is important to know that the email template is not just a file name but an identifier as well. So if you have a `templates/_mails/job_contact.twig` file, your ID for this template is `job_contact`

On you contact page you will need to place this row

```
{{ craft.email.templateInput('job_contact') | raw }}
```

This will tell 2 things to this plugin

- We have a `templates/_mails/job_contact.twig` file
- We have a `job_contact` key inside the `config/email_template_config.php` file

Now this file is important. Here you actually refer to the functions specified in PHPmailer. You use keys to refer to the methods, and values to fill out the data. I left an example in this repo: [https://raw.githubusercontent.com/cstudiossro/smtpmailer/main/email\_template\_config.php](https://raw.githubusercontent.com/cstudiossro/smtpmailer/main/email_template_config.php)

How to change the subject
-------------------------

[](#how-to-change-the-subject)

Put these line into your `email_template_config.php` file

```
    'test_template' => [
        //...
        'Subject' => 'Test Subject',
        //...
    ],
```

How to use google recaptcha?
----------------------------

[](#how-to-use-google-recaptcha)

Add this line to the .env file (you will need the recaptcha secret):

```
RECAPTCHA_SECRET=""
```

Put these line into your `email_template_config.php` file

```
    'test_template' => [
        //...
        'recaptcha' => [
            'setExpectedHostname' => ['example.com'],
            'setExpectedAction' => ['homepage'],
            'setScoreThreshold' => ['0.5']
        ],
        //...
    ],
```

After that, place this line into your form

```

```

What happens if recaptcha could not authenticate the user
---------------------------------------------------------

[](#what-happens-if-recaptcha-could-not-authenticate-the-user)

The page will return you to the email form, but you can retrieve the recaptcha error codes as follows:

```
{% set recaptchaErrorCodeString = craft.app.session.getFlash('recaptchaErrorCodes',null, true) $}
```

Error codes are separated by pipe, e.g.: missing-input-secret|missing-input-response
In twig 2 and 3, you can split it with this:

```
{% set recaptchaErrorCodes = recaptchaErrorCodeString|split('|') %}
```

List of all the possible recaptcha error codes: [https://developers.google.com/recaptcha/docs/verify#error\_code\_reference](https://developers.google.com/recaptcha/docs/verify#error_code_reference)

How to generate a contact form?
-------------------------------

[](#how-to-generate-a-contact-form)

```

    {# necessary fields #}
    {{ csrfInput() }}
    {{ redirectInput('/') }}
    {{ craft.email.templateInput('test_template') | raw }}

    {# custom fields #}
    What's your name?

    Which job are you applying for?

    What's your email address

    Send

```

How to generate email template?
-------------------------------

[](#how-to-generate-email-template)

```
You've received a new job application:
Name: {{ name }}
Job in question: {{ job }}
Applicant's email address: {{ email }}
```

How to use sendmail (instead of SMTP)?
--------------------------------------

[](#how-to-use-sendmail-instead-of-smtp)

Go into the `.env` file and copy the delivery\_protocol line here:

```
MAILER_DELIVERY_PROTOCOL=sendmail
```

How to send static files:
-------------------------

[](#how-to-send-static-files)

In your `email_template_config.php` file:

```
'addAttachment' => [
    Craft::getAlias('@webroot/photo.jpg')
],
```

The `@webroot` alias points towards your /web folder

> @webroot provides an absolute file system path, while @web only gives you a relative web path

How to send files from a form?
------------------------------

[](#how-to-send-files-from-a-form)

```
File 1

File 2

```

How do I send an autoreply email?
---------------------------------

[](#how-do-i-send-an-autoreply-email)

> Autoreply will go to the person who filled out your contact form

Paste these lines into your `email_template_config.php`, inside the template you want to have autoreply

```
'test_template' => [
    //...
    'replyConfig' => [
        'setFrom' => [
            //$mail->setFrom('from@example.com', 'From');
            ['from@example.com', 'From']
        ],
        //The name of the input field that stores the mail address to which the mail will go
        'setReplyInputName' => ['applicantEmailAddress'],
        //The name of the template, put it here: templates/_mails/
        'setReplyTemplate' => ['test_reply_template'],
    ],
    //...
]
```

On the contact form:

```
My email address

```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1403d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/91a0bac21c796aa3caaa0110086c0c8800f09168a73f0183e2e4c3a974c39281?d=identicon)[HunWalk](/maintainers/HunWalk)

---

Top Contributors

[![hunwalk](https://avatars.githubusercontent.com/u/32835435?v=4)](https://github.com/hunwalk "hunwalk (6 commits)")

---

Tags

emailmailertemplatesformcontactsmtp

### Embed Badge

![Health badge](/badges/cstudios-craft-smtpmailer/health.svg)

```
[![Health](https://phpackages.com/badges/cstudios-craft-smtpmailer/health.svg)](https://phpackages.com/packages/cstudios-craft-smtpmailer)
```

###  Alternatives

[aplus/email

Aplus Framework Email Library

2461.6M3](/packages/aplus-email)[craftcms/contact-form

Add a simple contact form to your Craft CMS site

295427.3k16](/packages/craftcms-contact-form)[putyourlightson/craft-campaign

Send and manage email campaigns, contacts and mailing lists.

6435.0k1](/packages/putyourlightson-craft-campaign)[markguinn/silverstripe-email-helpers

Silverstripe extension containing SMTP mailer class and some other classes for HTML emails

3145.4k1](/packages/markguinn-silverstripe-email-helpers)[putyourlightson/craft-amazon-ses

Amazon SES mailer adapter.

1190.4k2](/packages/putyourlightson-craft-amazon-ses)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
