Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To create a custom email, simply invoke Emails::sendCustom() with the appropriate parameters. The subject and body you provide may contain Template Parsing syntax as well. Use the $tags parameter to pass in variables to be substituted within the email subject and body. Using this method will automatically log the email to the database. To attached the email to a specific client use the $options parameter to specify the 'to_client_id' and 'from_staff_id'. This will allow you to view and resend the message under the client's profile.

Code Block
languagephp
title/plugins/my_plugin/controllers/admin_main.php
linenumberstrue
<?php
class AdminMain extends MyPluginController {

    public function index() {
        $this->uses(array("Emails"));

        $from = "no-reply@mydomain.com";
        $from_name = "My Company";
        $to = "jon.doe@yourdomain.com";
        $subject = "Subject of the email";
        $body = array(
            'text'=> "Hi {first_name},

This is your email."
        );
	$tags = array('first_name'=>"Jon");

        // Send the custom email
        $this->Emails->sendCustom($from, $from_name, $to, $subject, $body, $tags);
    }

}
?>

 

Template Emails

Plugins are free to take advantage of the email template system in Blesta. Doing so will allow staff members to update the content of the emails you intend to send from within the Emails section of the Company Settings. To create an email template use the EmailGroups::add() method. The $action parameter must be unique across all email templates, so prepending your plugin name is a good idea. For example, if your plugin is named FooBar then 'FooBar.notify_client' would make an excellent choice. As with custom emails, templates may also contain Template Parsing syntax.

...