PHP code example of openclerk / emails

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

    

openclerk / emails example snippets


Openclerk\Config::merge(array(
  "phpmailer_host" => "mail.example.com",
  "phpmailer_username" => "mailer",
  "phpmailer_password" => "password",
  "phpmailer_from" => "[email protected]",
  "phpmailer_from_name" => "Example Mailer",
  "phpmailer_reply_to" => "[email protected]",
  "phpmailer_bcc" => "[email protected]",   // if set, send a copy of all emails to this address

  // optional values
  // "emails_templates" => __DIR__ . "/../emails",
  // "emails_additional_css" => __DIR__ . "/../config/custom.css",
));

$user = Users\User::findUser(db(), 1);
if (!$user) {
  $user = "[email protected]";
}

$result = Emails\Email::send($user, "<id>", array(
  "now" => date('r'),
));

Openclerk\Events::on('email_sent', function($email) {
  // insert in database keys
  $q = db()->prepare("INSERT INTO emails SET
    user_id=:user_id,
    to_name=:to_name,
    to_email=:to_email,
    subject=:subject,
    template_id=:template_id,
    arguments=:arguments");
  $q->execute(array(
    "user_id" => $email['user_id'],
    "to_name" => $email['to_name'],
    "to_email" => $email['to_email'],
    "subject" => $email['subject'],
    "template_id" => $email['template_id'],
    "arguments" => serialize($email['arguments']),
  ));
});

function setUp() {
  Emails\Email::setMockMailer(array($this, "mockMailer"));
}

function tearDown() {
  Emails\Email::setMockMailer(null);
}

function mockMailer($to_email, $to_name, $subject, $template, $html_template) {
  // do your mock tests...
}