Hot answers tagged

14

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 configuration changes. Just set the Mandrill SMTP settings in the Craft admin area, and you're done.


13

EmailService->sendEmailByKey() sets the htmlBody property of EmailModel to this: $emailModel->htmlBody = "{% extends '{$template}' %}\n". "{% set body %}\n". $emailModel->htmlBody. "{% endset %}\n"; So if you've got a custom email template in craft/templates/email.html, in the control panel under Settings → Email → HTML Email Template,...


13

Edit: After the migration to Craft 3.1.x you should rather use this Code /** * @param string $html * @param string $subject * @param array|string|\craft\elements\User $mail * * @return bool */ public function sendMail(string $html, string $subject, $mail): bool { return Craft::$app ->...


12

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 in a plugin you can do: craft()->systemSettings->getSetting('email', 'emailAddress')


10

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


8

Currently there isn't a native function to do this. The only plugin that I know of that can do this, is Sprout Email from Barrel Strength Design. EDIT: I just released a plugin called Craft-Mailer which does what you are looking for.


8

If you are an administrator or your account has “administrate users” privileges, then there is a checkbox on the user’s edit page in the control panel that says “Require Password Reset on Next Login” which, if checked, will force the users to reset their password the next time they attempt to login. When creating a new account, if you leave the “Require ...


8

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.com', 'name' => 'Name') );


7

You can loop through a list of your recipients: // Comma-separated list of recipients $recipients = 'person1@example.com, person2@example.com'; // Break out recipients into an array $recipientList = explode( ",", $recipients ); // Create the globally known things about the EmailModel $email = new EmailModel(); $email->subject = 'My Email Subject'; $...


7

Currently there isn't a native way to do this, but you could write a plugin which would work like this: Wait for an event like: content.onSaveContent or entries.onSaveEntry Get all users from a specific usergroup using the ElementCriteriaModel. Use the EmailService to send a mail to each of them. . Quick-and-Dirty: public function init() { parent::...


7

Natively, there is no direct way to do this. It is possible, however, to easily create this functionality with a plugin... Build an ElementCriteriaModel which will return a list of all users. Organize that data into a batch (or multiple batches) of recipient email addresses. Use the EmailService API to generate an email to your selected recipients. ...


6

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 to a Section. If anybody has a specific need for it, I'd be glad to add features. More information: Brief


6

Yes there is, craft()->request->isCpRequest() returns whether the request is from the CP or not.


6

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 extend a basic HTML email wrapper, then inside my content block I did this: {% if emailKey == 'account_activation' %} {% include 'mail/activation' %} {% endif %...


5

The issue turned out to be the result of a variable name mistake on my part. I had typed in an incorrect variable name in the email template. I actually still don't really understand what that has to do with a database transaction, though. EDIT: If anyone else is running into a similar issue, I've found a way to get a more useful error message, as opposed ...


5

From that code snippet, it looks like you're needing nested arrays. Try setting your $email->cc property like this. $email->cc = array( array('name' => 'Your Name', 'email' => 'name@example.com') ); The code snippet is iterating over $email->cc as $cc as the first array, then going into cc['name'] and cc['email'] as a nested array.


5

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) { $user = $event->params['user']; if (!$user->admin) { $result = craft()->mailchimpSubscribe->subscribe($user->email, ''); ...


5

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 transactional emails: triggered and automated. Triggered emails are a one-off, context-specific email that get sent to a user when an event is triggered by a user'...


5

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.com, which is a Craft install. Make sure you're using smtp.mailgun.org as the host and that you've got the transport type set to TLS as well.


4

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.


4

Alternatively, you could get in touch with Ben Parizek of Barrel Strength Design who has a plugin called Sprout Email. Currently in beta but you can request a preview. I am using it as we speak.


4

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/


4

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 correctly loads Mailgun. So I guess it works, it's just (more than a little) ugly We have had success integrating Craft with MailGun in our plugins as well. While ...


4

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 URL (i.e., http://mysite.com/actions/myplugin/entriescreated/weekly), and run your job like that. Note, where you're accessing an action via cron you would ...


4

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 = new UserModel(); $user->email = 'sergster@abc.xyz'; $user->firstName = 'John'; // optional $user->lastName = 'Doe'; // optional craft()->email->...


4

I think you are referring to the System Email Address under "Settings" -> "E-mail" -> "System Email Address".


4

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 & postmaster. I would start with the contact form plugin, but modify it a bit so that it captures the users's information. Depending on your needs, I would ...


4

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 you need (or use a completely different library). I assume you don't want to cram everyone into to "To Address", so is the plan to set the "To Address" to ...


4

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"? Back many years ago, I'd send newsletters "manually" (using PHPList, pommo, my own home brewed set-up... shudders, etc), these were only a few hundred to a ...


4

If anyone comes here looking for this answer for Craft 3 the function you are looking for is Craft::$app->getRequest()->getIsCpRequest()


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