Versions Compared

Key

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

...

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 Company > 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.

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

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

        $group = array(
			'action' => "MyPluginsMyPlugin.custom_action",
			'type' => "staff",
			'plugin_dir' => "my_plugin",
			'tags' => "first_name,last_name"
		);

        // Add the custom group
		$group_id = $this->EmailGroups->add($group);


        $email = array(
			'email_group_id' => $group_id, 
			'company_id' => $this->company_id, 
			'lang' => "en_us", 
			'from' => "no-reply@mydomain.com", 
			'from_name' => "My Company",
            'subject' => "Subject of the email", 
			'text' => "Hi {first_name}, 
This is the text version of your email", 
			'html' => "<p>Hi {first_name},</p>
<p>This is the HTML version of your email</p>"
        );

        // Add an email to the group
		$this->Emails->add($email);

	}
}
?>

...

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

    public function index() {

		...
		
		$this->uses("Emails");

		$tags = array('first_name' => "Tommy", 'last_name' => "Callahan");
		$options = array('client_id' => 1020);
		$this->Emails->send("MyPluginsMyPlugin.custom_action", $this->company_id, "en_us", "tommy.callahan@yourdomain.com", $tags, null, null, null, $options);
	}
}
?>