Mail Class¶
The Mail class provides functions for the sending email via whatever protocol is specified in the site's Email configurations group.
Calling the Mail Class¶
$Mail = $this->Mail;
$Email = $this->Email;Sending an Email¶
$result = $this->Mail->address(array(
    'anton@example.com' => 'Anton'
))
->subject('Subject text')
->body('Email message')
->send();
echo $result; //Outputs (bool): trueReturns true if email was successfully sent or false if not.
Single email address without specifying username:
$this->Mail->address('anton@example.com');Single email address with specifying username:
$this->Mail->address(array(
    'anton@example.com' => 'Anton'
));Multiple email addresses:
$this->Mail->address(array(
    'anton@example.com' => 'Anton',
    'sergey@example.com' => 'Sergey',
    'test@example.com' => ''
));Sending Multiple Emails¶
$users_emails = array(
    'anton@example.com' => 'Anton',
    'sergey@example.com' => 'Sergey',
    'test@example.com' => ''
);
$errors = array();
foreach($users_emails as $email => $name){
    $result = $this->Mail->address(array(
        $email => $name
    ))
    ->subject('Subject text')
    ->body('Email message')
    ->send();
    if(!$result){
        $errors[] = $email;
    }
}
var_dump($errors);Sending an Email Using Template¶
Consider following `bulletin_add` email template in configurations table:
Dear {user_first_name},
Your bulletin has been added to {site_title}.
You can view your bulletin here:
{bulletin_path}
______________________________
{site_title} Team
{site_url}
{site_email}Replacing variables in template:
$replace = array(
    'user_first_name' => 'Anton',
    'user_email' => 'anton@example.com',
    'bulletin_path' => 'http://www.example.com'
);
$result = $this->Mail->address(array($replace['user_email'] => $replace['user_first_name']))
    ->tpl(array('tpl' => 'bulletin_add',
                'enh' => 'bulletin_board'
                ), $replace)
    ->send();$result = $this->Mail->address(array($replace['user_email'] => $replace['user_first_name']))
    ->tpl(array('tpl' => 'bulletin_add',
                'enh' => 'bulletin_board',
                'replace' => $replace
                ))
    ->send();Email message:
Dear Anton,
Your bulletin has been added to http://www.example.com
You can view your bulletin here:
http://www.example.com
______________________________
Vesthelm Team
http://www.example.com
test@example.com
Replaced variables by default:
{site_title} - conf('site_title', 'general')
{site_email} - conf('site_email', 'email')
{site_url} - V_URL