Ejemplo n.º 1
0
<?php

//Get the set of required files
require_once 'bootstrap.php';
use Queue;
use Database;
$objDB = new Database\Database($dbCredArray);
//Get the DB Object
$objProcessQueue = new Queue\ProcessQueue($objDB);
//Process Queue need DB for processing
if ($objProcessQueue->lockEmailsFromQueue(SERVER_NAME, MAX_MAILS_TO_READ)) {
    $emailArray = $objProcessQueue->getLockedEmails(SERVER_NAME);
    if (is_array($emailArray) && count($emailArray) > 0) {
        foreach ($emailArray as $key => $sendEmailArray) {
            //Setup the JSON for the Async Process execution
            $asyncParamsJSON = json_encode($sendEmailArray);
            //Initiate the Async Process with the configuration required
            $objProcessQueue->initiateAsyncThread($asyncConfigArray, 'postValue=' . $asyncParamsJSON);
        }
    }
}
<?php

require_once 'bootstrap.php';
use Queue;
use Database;
if (isset($_POST['postValue'])) {
    //Get the post Array to process
    $dataArray = json_decode($_POST['postValue'], true);
    //Create the Connection
    $objSwiftTransport = Swift_SmtpTransport::newInstance(SMTP_HOST, SMTP_PORT, SMTP_PROTOCOL)->setUsername(SMTP_USER)->setPassword(SMTP_PASSWORD);
    //Setup the Mailer Instance
    $objSwiftMailer = Swift_Mailer::newInstance($objSwiftTransport);
    //Create this Message
    $message = Swift_Message::newInstance($dataArray['subject'])->setFrom(array($dataArray['from_email_address']))->setTo(array($dataArray['to_email_address']))->setBody($dataArray['body'], 'multipart/alternative')->addPart($dataArray['body'], 'text/html')->addPart($dataArray['body'], 'text/plain');
    $objDB = new Database\Database($dbCredArray);
    //Get the DB Object
    $objProcessQueue = new Queue\ProcessQueue($objDB);
    //Process Queue need DB for processing
    // Send the message
    if ($objSwiftMailer->send($message)) {
        $updateStatus = $objProcessQueue->updateProcessStatus($dataArray['id'], SERVER_NAME, 3);
    } else {
        $updateStatus = $objProcessQueue->updateProcessStatus($dataArray['id'], SERVER_NAME, 4);
    }
}