WebMail Lite Documentation

Sending mail using PHP API

The following sample code allows for sending mail out using PHP API of WebMail Lite.

<?php
    
$sEmail = "user@domain.com";
$sTo = "recipient@server.com";
$sSubject = "Message subject";
$sBody = "<b>This is <i>my</i> message</b>";
$bHTML = true;
    
include './system/autoload.php';
\Aurora\System\Api::Init(true);
    
$oCoreDecorator = \Aurora\Modules\Core\Module::Decorator();
$oMailDecorator = \Aurora\Modules\Mail\Module::Decorator();
    
$oAccount = $oCoreDecorator->GetAccountUsedToAuthorize($sEmail);
    
try {
    $oMailDecorator->SendMessage($oAccount->EntityId, null, null, 0, [], "", $sTo, "", "", [], $sSubject, $sBody, $bHTML);
    echo "Message sent successfully";
}
catch(Exception $e)
{
    echo "Message could not be sent";
}

For this to work, user account denoted by $sEmail should exist in the database; SMTP authentication details for that account will be taken from the database.

If you need to send a plaintext email message, set $bHTML to false; if you're sending HTML email, its plaintext part will be built from HTML automatically.