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|...
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()
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 ...
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' %}
{% ...
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.
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 ...
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) {
...
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....
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'...
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 ...
4
votes
Accepted
Controlling where user is sent if clicking old or expired email activation link
It looks like the config setting activateAccountFailurePath is what you are looking for.
4
votes
Accepted
Sending email by key to non-user
Just because EmailService::sendEmailByKey() requires you to pass in a UserModel, doesn’t mean that the model has to represent an actual saved user. You can create one on the spot for them:
$user = ...
4
votes
Accepted
Email subscriptions system
Sounds quite do-able. I will first admit I don't know how postmaster works at all, so I could be way off in my suggestion. Regardless, you're looking at two plugins working together; a contact form &...
4
votes
Best way to bulk email an attachment?
As someone who's run a mail server professionally, thought I'd expand on a comment. Brad's answer goes over the technical details of sending with Craft, I suppose this answer is more "philosophical"?
...
4
votes
Best way to bulk email an attachment?
There's nothing that says you have to go through Craft's EmailModel/EmailService for this.
Craft ultimately uses the PHPMailer library, so you can instantiate it directly and use whatever settings ...
4
votes
Accepted
Change system settings email address
I think you are referring to the System Email Address under "Settings" -> "E-mail" -> "System Email Address".
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->...
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->...
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@ ...
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.
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 ...
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(...
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 ...
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% ...
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 ...
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 ...
3
votes
How to auto obfuscate email addresses in rich text field
I wrote a really quick Plugin for you to use that uses the _encodeStringRot13 function from the Sprout guys to use on any variable you want in Craft. What the Plugin does is to give you a new Twig ...
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')....
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 }}
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
emails × 199plugin-development × 32
craft3 × 26
users × 25
plugins × 14
registration × 13
activation × 13
templating × 11
plugin-craftcommerce × 11
plugin-contactform × 10
form × 7
config × 6
plugin-sproutemail × 6
plugin-freeform × 5
plugin-sproutforms × 5
settings × 5
user-profile × 4
control-panel × 3
events × 3
modules × 3
plugin-craftcommerce3 × 3
frontend-form × 3
order × 3
status × 3
smtp × 3