Email
    
            
            in package
            
        
    
    
    
Email class.
For make it easier to load mailer class with send mail configuration.
Tags
Table of Contents
Properties
- $baseFolder : string
 - $Container : Container
 
Methods
- __construct() : mixed
 - Class constructor.
 - __get() : mixed
 - Magic get.
 - getMailer() : PHPMailer
 - Initialize mailer class and configured it.
 - getMessage() : string
 - Get email message content and maybe replace the placeholder.
 
Properties
$baseFolder
    protected
        string
    $baseFolder
    
    
        The base folder (full path) to prepend to relative paths to images.
$Container
    protected
        Container
    $Container
    
    
    
    
    
Methods
__construct()
Class constructor.
    public
                    __construct(Container $Container) : mixed
    Parameters
- $Container : Container
 - 
                    
The DI container class. Only required for some method.
 
__get()
Magic get.
    public
                    __get(string $name) : mixed
    Parameters
- $name : string
 
getMailer()
Initialize mailer class and configured it.
    public
                    getMailer() : PHPMailer
    This method initialize the mailer class, setup configuration for it (mail, sendmail, smtp, smtp username & password, etc..).
It also setup sender address.
This method trigger exception for mailer. So, please use try..catch to catch the error message.
Tags
Return values
PHPMailer —Return mailer class to ready for set receipt address, subject, body message and send.
getMessage()
Get email message content and maybe replace the placeholder.
    public
                    getMessage(string $moduleName, string $messageFile[, array<string|int, mixed> $replaces = [] ]) : string
    It will be looking for "Module/[moduleName]/languages/email-messages/[messageFile]-[language].html" file.
This method can replace placeholder in the $replaces argument.
After called to this method, you can access the base folder (full path) that can be use for prepend to relative paths to images by call to $Email->baseFolder.
You can design email message by add any image related from the baseFolder.
Example: baseFolder is "Modules/MyModule", the image tag <img src="assets/img/logo.png"> will be call to "Modules/MyModule/assets/img/logo.pn".
Full example:
$Email = new \Rdb\Modules\RdbAdmin\Libraries\Email($this->Container);
$Mail = $Email->getMailer();
$Mail->addAddress('someone@address.tld', 'someone name');
$Mail->Subject = 'Forgot my password.';
$Mail->isHTML(true);
$replaces['%tokenvalue%'] = $tokenValue;
$emailMessage = $Email->getMessage('RdbAdmin', 'ForgotLoginPass', $replaces);
$Mail->msgHtml($emailMessage, $Email->baseFolder);
$Mail->AltBody = $Mail->html2text($emailMessage);
$Mail->send();
Parameters
- $moduleName : string
 - 
                    
The module name (case sensitive) that this email message file is in.
 - $messageFile : string
 - 
                    
The email message file without extension. Example: 'ForgotLoginPass' will be looking for 'ForgotLoginPass-[language].html'.
 - $replaces : array<string|int, mixed> = []
 - 
                    
The associative array for replace placeholder in message.
 
Tags
Return values
string —Return email message content.