GeniXCMS

Mail Class

categoryAPI edit_calendar31 Mar 2026

Mail Transmission Class


The Mail class is a high-level wrapper around the PHPMailer library. It simplifies the process of sending complex, multi-part emails (HTML and Plain Text) by abstracting the underlying transport mechanism — allowing your application to switch seamlessly between standard PHP mail() and authenticated SMTP relay.


⚡ Core Transmission Method

Mail::send(array $vars)

This is the primary way to dispatch communications from your modules or themes.

Parameter Type Required Description
to string Yes The recipient's email address.
to_name string No Display name for the recipient.
subject string Yes The header subject line of the email.
message string Yes The body content (HTML or Plain Text).
msgtype string No Content format: 'html' (default) or 'text'.

Returns: true on success, or a string containing the detailed error message from the mailer engine on failure.

$vars = [
    'to'      => '[email protected]',
    'to_name' => 'Clark Kent',
    'subject' => 'System Notification',
    'message' => '<h1>Update!</h1><p>Your content has been published.</p>',
    'msgtype' => 'html'
];

$result = Mail::send($vars);
if ($result !== true) {
    Log::error("Mail failed: " . $result);
}

⚙️ Configuration Schema

The behavior of the Mail engine is governed by the settings defined in Settings > E-Mail.

  • mailtype: Toggle between 0 (Local PHP Mail) and 1 (External SMTP Relay).
  • smtphost: The address of your SMTP provider (e.g., smtp.gmail.com).
  • smtpport: The connection port (usually 465 for SSL or 587 for TLS).
  • smtpuser: Your authentication username/email.
  • smtppass: Your authentication password.

🏗️ Internal Workflow

The Mail class performs several automated steps during transmission:

  1. Configuration Fetch: Retrieves all SMTP and Site parameters from the Options table.
  2. Engine Boot: Instantiates the PHPMailer object with the appropriate encryption (SSL/TLS).
  3. Sender Identification: Automatically uses the site's default name and email as the "From" identity.
  4. Error Handling: Wraps the transmission in an exception block, returning the raw error if the server rejects the request.

priority_high
ImportantSMTP Delivery: For high-volume or critical transactional emails (like password resets), it is strongly recommended to use a dedicated SMTP service (SendGrid, Mailgun, or Gmail) rather than the local PHP mail() function to avoid being flagged as spam.

See Also