Use PHPMailer in Custom Page

By default, PHPMaker uses server events to send emails automatically.
However, there are cases where you don’t want to send emails after
insert or edit
— like it’s implemented by default.

PHPMailer is already included in your PHPMaker project, so you can
easily send custom emails manually.


Step 1: Create a Custom Page

Create a custom page in PHPMaker (e.g. custommail) and paste the
following code:

<?php
// Send email on custom page in PHPMaker using PHPMailer
// CREATED BY VINTOICT – contact removed

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require './vendor/autoload.php';

$mail = new PHPMailer(true);

try {
    // Server settings
    // $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable debug output
    $mail->isSMTP();                              // Send using SMTP
    $mail->Host       = 'mail.xxxxxxx';           // SMTP server
    $mail->SMTPAuth   = true;                     // Enable SMTP auth
    $mail->Username   = 'support@yourdomain.com'; // SMTP username
    $mail->Password   = '***************';        // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // TLS encryption
    $mail->Port       = 465;                      // TCP port

    // Recipients
    $mail->setFrom('support@yourdomain.com', 'Your Company Name');
    $mail->addAddress('info@yourdomain.com', 'Your Company Name');
    // $mail->addAddress($email, $phone); // client email
    $mail->addReplyTo('support@yourdomain.com', 'Your Company Name');

    // Content
    $mail->isHTML(true);
    $mail->Subject = 'Service Subscription, Ref: ' . $slug;
    $mail->Body = '
    <!DOCTYPE html>
    <html>
    <head>
        <style>
            body { margin: 0; padding: 0; box-sizing: border-box; font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; }
            .receipt-container { max-width: 500px; background: white; border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); overflow: hidden; }
            .receipt-header { background-color: #006d5b; color: white; padding: 20px; text-align: center; }
            .receipt-body { padding: 25px; }
            .receipt-footer { padding: 15px 25px; background-color: #f9f9f9; text-align: center; font-size: 12px; color: #999; }
        </style>
    </head>
    <body>
        <div class="receipt-container">
            <div class="receipt-header">
                <h1>Welcome To Yoursite</h1>
                <p>Service Subscription</p>
            </div>
            <div class="receipt-body">
                <p><strong>Ref No:</strong> ' . $slug . '</p>
                <p><strong>Service:</strong> ' . $itemname . '</p>
                <p><strong>Student:</strong> ' . $buyername . '</p>
                <p><strong>Email:</strong> ' . $email . '</p>
            </div>
            <div class="receipt-footer">
                Please feel free to contact us for further queries.<br>
                <strong>Your Company Support</strong><br>
                Powered by Your Company
            </div>
        </div>
    </body>
    </html>';

    $mail->send();
    $success = 1;
} catch (Exception $e) {
    $error = 1;
}

Update your: - SMTP host\

  • Email credentials\
  • Message content

Once the page is loaded, it will send the email.


Step 2: How to Use

Static Usage

You can hardcode the content and include the mail page when needed:

if ($sendemail == 1) {
    include_once 'custommail.php';
}

Dynamic Usage

Pass parameters via URL and retrieve them in the custom mail page to
send emails dynamically.


Step 3: Use as API Endpoint

This is not using PHPMaker’s API actions — it simply works as a PHP
endpoint.
Any PHPMaker custom page can act as an endpoint if you return JSON.

Example:

function sendMemoEmail($to, $subject, $content, $from)
{
    $mail = new PHPMailer(true);
    try {
        // Server settings
        $mail->isSMTP();
        $mail->Host       = 'mail.yourdomain.com';
        $mail->SMTPAuth   = true;
        $mail->Username   = 'yourdomain@yourdomain.com';
        $mail->Password   = '********';
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
        $mail->Port       = 465;

        // Recipients
        $mail->setFrom('yourdomain@yourdomain.com', 'Company Name');
        $mail->addAddress($to);
        $mail->addReplyTo('yourdomain@yourdomain.com', 'Company Name');

        // Content
        $mail->isHTML(true);
        $mail->Subject = $subject;
        $mail->Body = "
        <!DOCTYPE html>
        <html>
        <head>
            <title>" . htmlspecialchars($subject) . "</title>
            <style>
                body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
                .memo-container { max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #ddd; border-radius: 5px; }
                .memo-header { background-color: #911f0f; color: white; padding: 15px; text-align: center; border-radius: 5px 5px 0 0; }
                .memo-content { padding: 20px; background-color: #f9f9f9; }
                .memo-footer { padding: 15px; text-align: center; font-size: 12px; color: #777; }
            </style>
        </head>
        <body>
            <div class='memo-container'>
                <div class='memo-header'>
                    <img src='img/applogo.png' alt='App Logo' style='max-width: 100px;'>
                    <h2>" . htmlspecialchars($subject) . "</h2>
                </div>
                <div class='memo-content'>{$content}</div>
                <div class='memo-footer'>
                    This is an automated message from the app. Please do not reply to this email.
                </div>
            </div>
        </body>
        </html>";

        $result = $mail->send();
        return $result;
    } catch (Exception $e) {
        error_log("Email sending failed: " . $e->getMessage());
        return false;
    }
}

if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    echo json_encode(['success' => false, 'message' => 'Method not allowed']);
    exit;
}

Step 4: Notes for Using Custom Pages as API Endpoints

To make your custom page work correctly as an endpoint in PHPMaker:

  1. Return JSON

  2. Add exit(); at the end of your code

  3. Remove:

    // Page object
    $yourpagename = &$Page;
    
  4. Remove:

    <?php $Page->showMessage(); ?>
    

If you follow these steps strictly,
you’ll be able to send emails using a custom PHPMaker page and also use
it as an API-like endpoint.

  1. Make very sure you have added security checking code to the custommail.php. It is recommended that you move your code to Route_Action or Api_Action server event (for <= v2025) or to RouteActionController.php or ApiActionController.php (for v2026).
  2. From v2025+, PHPMailer is not available unless you have enabled the advanced setting Use PHPMailer.