PHP code example of programster / email-logger

1. Go to this page and download the library: Download programster/email-logger 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/ */

    

programster / email-logger example snippets


use Programster\EmailLogger\EmailLogger;
use Programster\EmailLogger\EmailSubscriber;
use Programster\Phpmailer\Contact;
use Programster\Phpmailer\PhpMailerEmailer;
use Programster\Phpmailer\SecurityProtocol;

# Create an emailer, in this case using PHPMailer.
# Any emailer that implements \Programster\Phpmailer\EmailerInterface will work
$emailer = new PhpMailerEmailer(
    smtpHost: "smtp.gmail.com",
    smtpUser: "[email protected]",
    smtpPassword: "app-specific-password-goes-here",
    securityProtocol: SecurityProtocol::TLS,
    from: new Contact("[email protected]", "Senders Name"),
    smtpPort: 587,
    replyTo: new Contact("[email protected]", "noreply"),
);

# Create the email logger
$logger = new EmailLogger(
    $emailer,
    "my-service-name-here",
    new EmailSubscriber("Jenn", "[email protected]"),
    new EmailSubscriber("Roy", "[email protected]"),
);

# Create some useful context for the log that might help debugging/resolving what went wrong...
$context = [
    'some' => 'details'
];

# Send the log (email)
$logger->critical("There was a critical error!", $context);