Skip to Content search facebook instagram pinterest twitter youtube

Sending email

SproutCMS has an inbuilt system for sending rich-text (i.e. HTML) emails using Views, similar to the way that controller methods and widgets work.

Here's an example:


function sendWelcomeEmail($member_id)
    $mem = Pdb::get('members', $member_id);
    $view = new View('modules/Members/email/welcome');
    $mail = new Email();
    $mail->Subject = 'Hello there, new member!';
    $mail->addAddress($mem['email'], "{$mem['first_name']} {$mem['last_name']}");

The view could look something like this:


use Sprout\Helpers\Enc;
<p>Hi <?= Enc::html($first_name); ?>,</p>
<p>We like you, so please use this promo code for free stuff: <?= Enc::html($promo_code); ?></p>

Easy as pie, right?

But this is only the content of the message. The main skin is specified as the third template, which defaults to 'skin/email'.

Generally you only need a single email skin per site, but you can use multiple if you ever want to.