Hot answers tagged

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|...
14 votes
Accepted

How do I set up Craft to send emails from my local MAMP/Virtual Host X dev environment

These days I just use Mandrill. It's simple to set up, free unless you're sending tens of thousands of emails, and you can continue to use it on any development (or production) machine without any ...
14 votes
Accepted

Pass content of system messages to HTML Email Template

EmailService->sendEmailByKey() sets the htmlBody property of EmailModel to this: $emailModel->htmlBody = "{% extends '{$template}' %}\n". "{% set body %}\n". $emailModel->htmlBody. ...
  • 66.5k
13 votes
Accepted

How do I get the Settings System email Address?

You can get this in a template like so: {# returns an array of your email settings #} {% set settings = craft.systemSettings.email %} {# returns the email address #} {{ settings.emailAddress }} And ...
  • 4,519
10 votes
Accepted

Passing Entry to craft()->templates->render()

You can just pass in the EntryModel straight to the view. $html = craft()->templates->render('path/to/template', [ 'entry' => $entryModel ]);
  • 2,957
9 votes
Accepted

How to set CC or BCC emails to EmailModel?

The way you do it now only adds email addresses as an array. You'll have to specify both email and name keys too, so it becomes like this: $email->cc = array( array('email' => 'email@email....
9 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

Email Notification When Post Submitted

For those that are looking for a plugin that simply notifies users (without all the overhead), take a look at Brief. It's a super-light plugin that simply notifies users whenever a new entry is added ...
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.
  • 35.9k
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 ...
  • 13.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) { ...
  • 35.9k
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....
  • 66.5k
4 votes

What can we do to help avoid member activation emails going to spam?

This the best article I've read on reliably delivering emails through code: http://blog.codinghorror.com/so-youd-like-to-send-some-email-through-code/
  • 66.5k
4 votes
Accepted

Activate account email {{link}}

OK, just did a quick look through the docs. Appears that this can be set via the config file. Link to documentation There's also the option to set whether the user is logged in automatically.
  • 438
4 votes

Using Mailgun with Craft

The asker was able to solve their question and confirm that MailGun can be used with Craft. In the comment they state: Just FYI: requiring vendor/autoload.php (from my plugin) worked and ...
  • 13.3k
4 votes
Accepted

Is it possible to have Craft send an email on page load?

I would think you would want to instead set up a controller action, as URLs route directly to them, rather than use the overhead of a page. Your cron job could hit the corresponding Controller Action ...
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

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.
  • 608
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".
  • 2,824
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,696
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 ...
  • 66.5k
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"? ...
  • 6,502
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,361
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.
  • 66.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 ...
  • 4,696
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(...

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