Core Boxx – Mail Pagination Settings Library Reference

NOTES

  • Change EMAIL_FROM in the settings database table if you want to change the “email from”.
  • The mail library uses the default PHP mail(). Feel free to rebuild the entire library if you want to use other libraries such as PHPMailer.

 

BASIC SEND MAIL

$_CORE->load("Mail");
echo $_CORE->Mail->send([
  "from" => "sys@site.com",
  "to" => "job@doe.com",
  "cc" => "joe@doe.com", // OPTIONAL
  "bcc" => "jon@doe.com", // OPTIONAL
  "subject" => "Test Email",
  "body" => "This is a <strong>TEST</strong> email",
  "attach" => "PATH/IMAGE.JPG" // OPTIONAL
]) ? "OK" : $_CORE->error ;

// TO, CC, BCC CAN ALSO BE AN ARRAY OF EMAIL
// "to" => ["jac@doe.com", "jan@doe.com", "jay@doe.com"]
// ATTACH CAN ALSO BE AN ARRAY OF FILES
// "attach" => ["FILE-1", "FILE-2"]

Yep, send() is all you need. The bare minimum is to specify the from, to, subject, and body.

 

 

EMAIL WITH HTML TEMPLATE

HTML Template
<html><body>
  <h1>Welcome!</h1>
  <p>Thank you for joining <?=$name?>. Here is your discount code <?=$code?></p>
</body></html>
Use HTML Template
$_CORE->Mail->send([
  "from" => "sys@site.com",
  "to" => "Jon@doe.com",
  "subject" => "Welcome",
  "template" => "template.php",
  "vars" => ["name"=>"Jon", "code"=>"123ABC"]
]);

Take note, if body and template exist at the same time, template will take precedence.

 

PAGINATION EXAMPLE

The Library
class Dummy extends Core {
  function get ($page=1) {
    // (A) PAGINATION
    $this->core->paginator(
      $this->DB->fetchCol("SELECT COUNT(*) FROM `TABLE`"), $page
    );

    // (B) FETCH
    return $this->DB->fetchAll(
      "SELECT * FROM `TABLE`" . $this->core->page["lim"]
    );
  }
}
HTML Page
<div id="demo"></div>
<script> 
function jsgoto (pg) {
  cb.load({
    page : "PHP-BELOW",
    target : "demo",
    data : { page : pg }
  });
}
window.onload = () => { jsgoto(1); };
</script>
PHP
<?php
// (A) GET ENTRIES
$_CORE->load("Dummy");
$entries = $_CORE_>Dummy->get($_POST["page"]);

// (B) DRAW HTML
foreach ($entries as $e) { ... }
 
// (C) DRAW PAGINATION
$_CORE->load("Page");
$_CORE->Page->draw("jsgoto");

 

 

SETTINGS LIBRARY

function __construct()
Loads and sets all settings from the database with setting_group=1.
function defineG($group)

Get all group settings from the database and run PHP define(NAME, VALUE).

  • $group – Integer, group ID.
$_CORE->Settings->defineG(1);
function defineN($name)

Get specified settings from the database and run PHP define(NAME, VALUE).

  • $name – String, setting name. Or an array of setting names.
$_CORE->Settings->defineN("PAGE_PER");
$_CORE->Settings->defineN(["SETTINGA", "SETTINGB"]);
function getAll($group=1)

Get all settings in the specified group.

  • $group – Integer, group ID.
$settings = $_CORE->settings->get();
function save($setting)

Save the given settings.

  • $settings – Array, in the format of [NAME => VALUE, NAME => VALUE].
$CORE->settings->save([
  "EMAIL_FROM" => "jon@doe.com",
  "PAGE_PER" => 30
]);

Leave a Comment

Your email address will not be published.