PPPHP

Email API – Email Class

The Email class sends emails via SMTP using app passwords or custom credentials. Provider presets for Gmail, Outlook, Yahoo, and Custom SMTP are built in. All sending is done through raw PHP sockets — zero external dependencies.

Contents

Configuring Email Settings

Email settings are stored in the Misc module (Email tab) and saved into project.json. You can also set them programmatically:

use PpPhp\Core\Email;

Email::setSettings([
    'provider'    => 'gmail',
    'host'        => 'smtp.gmail.com',
    'port'        => 587,
    'encryption'  => 'tls',
    'username'    => 'you@gmail.com',
    'password'    => 'your-16-char-app-password',
    'fromAddress' => 'you@gmail.com',
    'fromName'    => 'Your App',
]);

Sending an Email

$result = Email::send([
    'to'      => 'user@example.com',
    'subject' => 'Welcome',
    'body'    => 'Thank you for registering!',
]);

if ($result['mailed']) {
    echo 'Sent!';
} else {
    echo 'Error: ' . $result['message'];
}

HTML Emails

$result = Email::send([
    'to'       => 'user@example.com',
    'subject'  => 'Your Order',
    'htmlbody' => '<h1>Order Confirmed</h1><p>Your order #1234 has been shipped.</p>',
]);

CC, BCC, and Reply-To

$result = Email::send([
    'to'      => 'user@example.com',
    'subject' => 'Project Update',
    'body'    => 'Here is the latest update...',
    'cc'      => 'manager@example.com',
    'bcc'     => 'archive@example.com',
    'replyTo' => 'support@example.com',
]);

Attachments

$result = Email::send([
    'to'          => 'user@example.com',
    'subject'     => 'Invoice',
    'body'        => 'Your invoice is attached.',
    'attachments' => [
        ['path' => '/tmp/invoice.pdf', 'name' => 'Invoice_May.pdf'],
        ['path' => '/tmp/receipt.png', 'name' => 'Receipt.png'],
    ],
]);

Priority

$result = Email::send([
    'to'       => 'user@example.com',
    'subject'  => 'Urgent: Action Required',
    'body'     => 'Please respond immediately.',
    'priority' => 1,   // 1 = highest, 5 = lowest
]);

Testing the Configuration

Use the Test Email button in the Misc module's Email tab, or programmatically:

// Send a quick test
$result = Email::send([
    'to'      => 'you@gmail.com',
    'subject' => 'Test from pp-php',
    'body'    => 'Your email configuration is working!',
]);

echo $result['mailed'] ? 'OK' : $result['message'];

Provider Presets

ProviderHostPortEncryptionNotes
Gmailsmtp.gmail.com587TLSRequires App Password (myaccount.google.com/apppasswords)
Outlooksmtp-mail.outlook.com587TLSOAuth 2.0 required for most accounts
Yahoosmtp.mail.yahoo.com465SSLApp Password under "External connections"
Custom587TLSAny SMTP server

Troubleshooting


🔗 Related Help Topics

SMS API Notification API Database API