This mail queue created for organising your mail queue and making your server more easer. By using Mail Queue class you can :
- Add sender and receiver your queue
- In your cron jobs files or another set mailer and run queue
- You can watch your mail status from your database and resend your mail to your customer or someone else
You can download as a .zip file by clicking above or clone this repository :
git clone https://github.com/selbil/mail-queue.git
You can use this class from composer
composer require "selbil/mail-queue":"dev-master"
main.php
// Use it because of truer sending and log
date_default_timezone_set("Europe/Istanbul");
// Require or include your composer autoloader
require_once "vendor/autoload.php";
$queueConfig = [
"dbname" => "my_queue_test_db",
"sender" => "emredoganm@live.com",
];
// SelBil Mail Queue uses this default config, you can customize it with setConfig() function
/*
public $defaultConfig = [
"host" => "localhost",
"port" => 3306,
"dbname" => "your-db-name",
"charset" => "UTF8",
"username" => "root",
"password" => "root",
"table" => "mail_queue",
"sender" => NULL,
"senderName"=> NULL,
"reply" => NULL,
"replyNAme" => NULL
];
*/
$queue = new Selbil\MailQueue\Queue;
// Set your database config and create schema for mail queue
// SelBil Mail Queue uses MySQL
$queue->setConfig($queueConfig)
->createSchema();
cron-for-queue.php
date_default_timezone_set("Europe/Moscow");
require 'vendor/autoload.php';
// We are re-initilizating our database config file for reading
$config = [
"dbname" => "your-db-name",
];
// These are for your smtp mail server config
// I am using my Gmail account for testing
$mailConfig = [
"host" => "smtp.gmail.com",
"username" => "emredoganm06@gmail.com",
"password" => "my-beautiful-password"
];
$mailer = new Selbil\MailQueue\Mail;
// Database config registration
$mailer->setDatabaseConfig($config);
// Mailer config registration
$mailer->setConfig($mailConfig);
// Number of mail for one cycle
$mailer->setLimit(5);
// Run the query for your customers or users
$mailer->run();
This repository uses PHPMailer and all of its components for easier mail sendings. You can read the documentation of PHPMailer from https://github.com/PHPMailer/PHPMailer/wiki/Tutorial
Selbil Mail Queue use PHPMailer instance in Mail
class as public $mailer
variable. You can use all the features after setting Mail class config.
Thank you for support!