PHP code example of benjosiah / smtp-express-php

1. Go to this page and download the library: Download benjosiah/smtp-express-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

benjosiah / smtp-express-php example snippets



use SmtpExpress\SmtpExpress;
r-project-secret');


use SmtpExpress\Mail\SendMail;

$email = (new SendMail())
    ->subject('Welcome To Express')
    ->message('<h1>Hello from SMTP Express</h1><p>Enjoy fast email delivery!</p>')
    ->sender('[email protected]', 'SMTP SERVER')
    ->recipients('[email protected]', 'Ben Josiah');

$response = $smtp->sendEmail($email);



use SmtpExpress\Mail\SendMail;
use SmtpExpress\Templates\Template;
use SmtpExpress\Templates\TemplateRenderer;

// Load HTML template
$template = new Template(file_get_contents('email.html'));

// Render with variables
$renderer = new TemplateRenderer();
$html = $renderer->render($template, [
    'name' => 'Josiah',
    'company' => 'SMTPExpress Inc.',
    'url' => 'https://yourapp.com/reset-password'
]);

// Build email
$email = (new SendMail())
    ->subject('Welcome To Express')
    ->message($html)
    ->sender('[email protected]', 'SMTP SERVER')
    ->recipients('[email protected]', 'Ben Josiah');

$response = $smtp->sendEmail($email);



use SmtpExpress\Mail\SendMail;

$templateEmail = (new SendMail())
    ->subject('A Template message from the express')
    ->template('template-id', [
        'name' => 'Josiah',
        'company' => 'SMTP Express',
        'url'=> 'https://yourapp.com/reset-password'
    ])
    ->sender('[email protected]', 'SMTP SERVER')
    ->recipients('[email protected]', 'Ben Josiah');

$response = $smtp->sendEmail($templateEmail);



use SmtpExpress\Mail\SendMail;

$calendarEmail = (new SendMail())
    ->subject('Strategy Sync-up')
    ->message('<p>Let’s meet to discuss our project roadmap.</p>')
    ->sender('[email protected]', 'SMTP SERVER')
    ->recipients('[email protected]', 'Ben Josiah')
    ->calendarEvent(
        'Strategy Sync-up',
        '2024-01-18T23:00:00.000Z',
        '2024-01-19T23:00:00.000Z'
    );

$response = $smtp->sendEmail($calendarEmail);


use SmtpExpress\Exception\SmtpExpressException;

try {
    $smtp->sendEmail($email);
} catch (SmtpExpressException $e) {
    echo 'Failed to send: ' . $e->getMessage();
}

bash
composer 

.
├── src/
│   ├── Mail/
│   │   └── SendMail.php
│   ├── Templates/
│   │   ├── Template.php
│   │   └── TemplateRenderer.php
│   ├── Exception/
│   │   └── SmtpExpressException.php
│   └── SmtpExpress.php