/**
 * Grab and push test email data into redis
 * @param $limit_rounds number of times function will execute recursively
 * @param $time_between_rounds number of seconds between each recursive round.
 */
function init($limit_rounds = 10, $time_between_rounds = 5)
{
    $limit_rounds--;
    $email_data_array = json_decode(exec('node test/make-test-data.js 100'));
    foreach ($email_data_array as $key => $email_data_item) {
        queue_email($email_data_item, rand(0, 10));
    }
    if ($limit_rounds > 0) {
        echo "queue_email sleeping. Rounds left: {$limit_rounds}.";
        sleep($time_between_rounds);
        init($limit_rounds);
    }
}
示例#2
0
     curl_setopt($s, CURLOPT_URL, $nextpage);
     curl_setopt($s, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($s, CURLOPT_USERAGENT, 'nuQuery/1.0 (Emailbot)');
     # Our return data type
     $return_data = PostParser::decode(curl_exec($s), NQ_DEFAULT_CONTENT_TYPE);
     curl_close($s);
     # Looping through the results
     foreach ($return_data->results as $record) {
         # Setting up the variables
         $variables = json_decode($db_queue['variables']);
         foreach ($record as $key => $value) {
             $variables->{$key} = $value;
         }
         # Adding the email to the queue
         $result = queue_email($G_CONTROLLER_DBLINK, $record->{$db_queue['recipient_column']}, $db_queue['sender_email'], $db_queue['subject'], $email_data, $constants, $variables, $db_queue['app_id'], strtotime($db_queue['send_date']), false);
         # Tracking
         if ($result == 1) {
             $sent++;
         } elseif ($result == -1) {
             $blocked++;
         }
     }
     # If we have a next page
     $nextpage = isset($return_data->nextpage) && $return_data->nextpage != '' ? $return_data->nextpage : '';
 }
 # Adding to our archive
 $query = "\tINSERT IGNORE INTO\n\t\t\t\t\t" . NQ_EMAIL_DATABASE_QUEUE_ARCHIVE_TABLE . "\n\t\t\t\t\t(\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t*,\n\t\t\t\t\t\t\tNOW()\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t" . NQ_EMAIL_DATABASE_QUEUE_TABLE . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`id`=" . (int) $db_queue['id'] . "\n\t\t\t\t\t)";
 mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
 # Deleting our queue item
 $query = "\tDELETE FROM\n\t\t\t\t\t" . NQ_EMAIL_DATABASE_QUEUE_TABLE . "\n\t\t\t\tWHERE\n\t\t\t\t\t`id`=" . (int) $db_queue['id'] . "\n\t\t\t\tLIMIT 1";
示例#3
0
$result = mysqli_multi_result_query($G_STORAGE_CONTROLLER_DBLINK, $query);
$constants = mysqli_fetch_all($result, MYSQLI_ASSOC);
# Letting our user know whats going on
$content = new stdClass();
$content->success = true;
$content->sent = 0;
$content->blocked = 0;
# Sending our email
$subject = isset($_JPOST->subject) && $_JPOST->subject != '' ? $_JPOST->subject : $email_data['subject'];
$send_time = isset($_JPOST->send_time) && $_JPOST->send_time != '' ? strtotime($_JPOST->send_time) : time();
$email->personal = $email->personal == '' ? $G_APP_DATA['name'] : $email->personal;
$from = $email->personal . ' <' . $email->mailbox . '@' . $email->host . '>';
# Sending our emails
foreach (is_array($_JPOST->recipients) ? $_JPOST->recipients : explode(',', $_JPOST->recipients) as $email) {
    # Adding (or not) to queue
    $result = queue_email($G_STORAGE_CONTROLLER_DBLINK, $email, $from, $subject, $email_data, $constants, $_JPOST->variables, $G_APP_DATA['id'], $send_time);
    # Sent
    if ($result == 1) {
        $content->sent++;
    } elseif ($result == -1) {
        $content->blocked++;
    }
}
# Sending our content
PostParser::send($content);
/* --- Connection closed wit PostParser::send --- Below this point things need to be tracked and cleaned up --- */
# Closing the storage connection
mysqli_shared_close($G_STORAGE_CONTROLLER_DBLINK, $G_SHARED_DBLINKS);
# Closing controller if tracking is different
if (NQ_CONTROLLER_HOST != NQ_TRACKING_HOST) {
    mysqli_shared_close($G_CONTROLLER_DBLINK, $G_SHARED_DBLINKS);