Skip to main content
22 votes
Accepted

How to send email from Craft 3 custom plugin?

Edit: After the migration to Craft 3.1.x you should rather use this Code /** * @param string $html * @param string $subject * @param array|...
Robin Schambach's user avatar
11 votes

Is there a way to detect if a action is triggered from a control panel form?

If anyone comes here looking for this answer for Craft 3 the function you are looking for is Craft::$app->getRequest()->getIsCpRequest()
nfourtythree's user avatar
8 votes
Accepted

Customize activation and other system emails

Actually Brad, I was able to figure out a way to do this with some help from @carlcs in the slack channel. I defined an "HTML Template" in the main email settings screen, then in that template I ...
Rick Kukiela's user avatar
7 votes
Accepted

How to use the default HTML email template when sending an email from a plugin?

There are different ways Extending the E-mail template in your template This could be your email template emails/_someMail {% extends 'path/of/your/layout-same-as-you-inserted-in-your-cp' %} {% ...
Robin Schambach's user avatar
6 votes

How to build a transactional email platform with Craft

This answer will focus on using Sprout Email for transactional emails. Transactional Emails First, a comment on semantics. I feel the question above is drawing a distinction between two types of ...
Ben Parizek's user avatar
  • 13.5k
6 votes
Accepted

Is there a way to detect if a action is triggered from a control panel form?

Yes there is, craft()->request->isCpRequest() returns whether the request is from the CP or not.
carlcs's user avatar
  • 36.3k
5 votes
Accepted

Automatically subscribe users to MailChimp list?

Install the MailChimp Subscribe plugin and add the following users.onActivateUser event listener to your site’s Business Logic plugin. craft()->on('users.onActivateUser', function(Event $event) { ...
carlcs's user avatar
  • 36.3k
5 votes

Mailgun (SMTP) + Craft

Craft is just passing on the error message it gets back when trying to connect with whatever settings it was given. And we're using Mailgun ourselves (port 587) for sending emails on https://craftcms....
Brad Bell's user avatar
  • 67.5k
5 votes

Send entry as HTML email

You would need to attach such functionality to EVENT_AFTER_SAVE event in the custom php module. The module can be built using plugin factory website. For attaching functionality to the event, you don'...
Piotr Pogorzelski's user avatar
5 votes

Send email notification to admins when a new entry is created

You can do this with a simple module. You can set one up at pluginfactory.io with no controllers and a service called Email. If you're unsure about how modules work or how to set one up, I can highly ...
Martin Spain's user avatar
  • 1,529
4 votes

EmailService now has Twig render email messages in safe mode

OK so it's pretty easy to pass additional variables to the email template using the email.onBeforeSendEmail event: craft()->on('email.onBeforeSendEmail', function(Event $event) { $event->...
Mike Pepper's user avatar
  • 4,391
4 votes
Accepted

Only allow signups from people with @___.com emails

One way of doing this is to write a custom plugin that intercepts the users.onBeforeSaveUser event. You would check that the submitted email address matched your desired pattern and set $event->...
Steve Rowling's user avatar
4 votes
Accepted

Mailgun (SMTP) + Craft

So it turns out this was a server issue due to cPanel... A few solutions for people may run in to this in future... Set email settings to remote on server Update MX entries on server Add postmaster@ ...
Jason Mayo's user avatar
4 votes
Accepted

Can I set an environment var for SMTP mail servers?

Not an easy way to do this in Craft 2, but this is possible in the upcomgin Craft 3 (currently in beta) using craft/config/app.php, which is multi-environment aware.
Brad Bell's user avatar
  • 67.5k
4 votes
Accepted

Send email to website owner after user registration

I have done something very similar. You'll want to create a plugin for this. In my case, I am validating email addresses so I was checking against the onBeforeActivateUser event. If you are not ...
Damon's user avatar
  • 4,706
4 votes
Accepted

Sending a custom email in the users prefered locale

You can translate string in PHP and Twig via translate function public static function t($message, $variables = array(), $source = null, $language = null, $category = 'craft') Twig {{ 'my string'|t(...
Robin Schambach's user avatar
4 votes

How to change the Craft 3 activation email?

Under Settings > Email there is a field called "HTML Email Template" which you can use to point to a single template that handles all of the system emails. It's not very obvious from the Craft UI, but ...
James Smith's user avatar
  • 5,344
4 votes

Main email address for "Contact Us" in settings is not changing

If you are using the popular 'Contact Form' plugin, try Settings > Contact Form (under Plugins heading) and the field you want is the first field, 'To Email'. The variables in Globals are 100% ...
pixelace's user avatar
4 votes
Accepted

How to set SMTP Enrcyption with an environment variable

You can name the environment variable whatever you want. The trick is that the variable's value needs to be either none, ssl or tls (i.e. the three options that are supported for the "Encryption ...
Mats Mikkel Rummelhoff's user avatar
4 votes

Questions about newsletters & warning message on my interface

I would like to send an email to all the Architect Declare's French members. Is it possible to do this in the form of a newsletter? Craft doesn't have any newsletter-like features out of the box. You ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

How to do an ajax submission to Craft Contact Form with attachments using FormData?

I have it working now using this: $('#Form').submit(function(ev) { // Prevent the form from actually submitting ev.preventDefault(); var formData = new FormData($(this)[0]); // Send it to the ...
SteveO's user avatar
  • 336
3 votes
Accepted

Unverified emails blocking user registration

I'm not sure that I agree with your analysis. At a minimum maybe it's a feature request with a config setting to change the behavior. But if you're really concerned about the behavior, you can ...
Brad Bell's user avatar
  • 67.5k
3 votes
Accepted

How to subscribe to an entry and get notified by email in case of new comments?

I really like the idea of using a simple plugin like Like to keep track of what entries users are interested in. But instead of writing the code to integrate with Postmaster, I’d probably just use ...
carlcs's user avatar
  • 36.3k
3 votes
Accepted

EmailService now has Twig render email messages in safe mode

As of Craft 2.6.2916, the email fields are no longer ran through Twig's safe mode. EmailService no longer has Twig render email messages in safe mode, which was a little heavy-handed and prevented ...
Brad Bell's user avatar
  • 67.5k
3 votes

How do I get the Settings System email Address?

The craft.systemSettings variable was been deprecated as of Craft 3.1.0, and removed in Craft 4.0. Here's how to get the system email address in Craft 3.1.0+: {{ craft.app.projectConfig.get('email')....
Mats Mikkel Rummelhoff's user avatar
3 votes

How do I get the Settings System email Address?

In craft 3 it appears you can access it by doing the following: {{ craft.systemSettings.email.fromEmail }}
jnowland's user avatar
  • 846
3 votes

Setting system email address and sender name in multi config

Marion's answer is a workaround for Craft 2, but this has been officially addressed in the upcoming Craft 3: https://github.com/craftcms/cms/issues/840
Brad Bell's user avatar
  • 67.5k
3 votes
Accepted

Setting system email address and sender name in multi config

The testToEmailAddress config setting which Configures Craft to send all system emails to a single email address (or multiple email addresses), for testing purposes. sounds like the one you are ...
Marion Newlevant's user avatar
3 votes
Accepted

Render Template issue

The template path needs to include your plugin folder name. So in your case the path to your email templates would be pluginname/templates/emails/prospect and the path you pass to render() would be ...
Luke Pearce's user avatar
  • 3,863
3 votes

Integrate Google reCAPTCHA into Contact Form plugin

There are several anti-SPAM form plugins available for Craft that should work for you (including a Google reCAPTCHA one).
Brad Bell's user avatar
  • 67.5k

Only top scored, non community-wiki answers of a minimum length are eligible