Exemplo n.º 1
0
 function mailmanager_go_send_email($email_id, $recipient_list)
 {
     global $wpdb;
     $email = 'SELECT * FROM ' . $wpdb->prefix . 'mm_email WHERE id = ' . $email_id;
     $email = $wpdb->get_results($email);
     foreach ($email as $e) {
         $data = $e->body;
         $data = json_decode($data);
         // go
         $this->getresponse->send_newsletter($data->campaign_id, $data->from_email_id, $data->email_subject, $data->contents, $data->flags, FALSE, $data->paras, FALSE, FALSE);
         mailmanager_log_email_send($user_id, '100' . $email_id);
         $query = 'DELETE FROM ' . $wpdb->prefix . 'mm_email WHERE id = ' . $email_id;
         $wpdb->query($query);
     }
 }
Exemplo n.º 2
0
function mailmanager_check_series_queue()
{
    $mm_action = $_GET['mm_action'];
    if ($mm_action) {
        echo __('The MM Check Series Queue is being manually run', 'ym_mailmanager') . '<br />';
    }
    global $wpdb;
    // contains a element with target email_id
    $emails_to_send = array();
    //get series
    $sql = 'SELECT id, recipient_list FROM ' . $wpdb->prefix . 'mm_series WHERE enabled = 1';
    foreach ($wpdb->get_results($sql) as $row) {
        //get target users
        if ($sql = mailmanager_get_sql($row->recipient_list)) {
            if ($users = $wpdb->get_results($sql)) {
                foreach ($users as $i => $user) {
                    if ($mm_action) {
                        echo '<br />' . __('Found', 'ym_mailmanager') . ' ' . $user->email;
                    }
                    //add users not in table
                    $user_id = mailmanager_get_user_id($user->email);
                    // when did user join series
                    $user_join = mailmanager_get_user_in_series($user_id, $row->id, $row->recipient_list);
                    if ($user_join) {
                        if ($mm_action) {
                            echo ' ' . __('user is subscribed', 'ym_mailmanager');
                        }
                        // get what has been sent to this users
                        $sql = 'SELECT email_id FROM ' . $wpdb->prefix . 'mm_email_sent WHERE user_id = ' . $user_id;
                        $ignore = array();
                        foreach ($wpdb->get_results($sql) as $sent) {
                            $ignore[] = $sent->email_id;
                        }
                        // series emails
                        $sql = 'SELECT email_id, delay_days FROM ' . $wpdb->prefix . 'mm_email_in_series WHERE series_id = ' . $row->id;
                        $emails = array();
                        $one_day = 86400;
                        foreach ($wpdb->get_results($sql) as $email) {
                            $offset = $email->delay_days * $one_day;
                            $send_email = $user_join + $offset;
                            // already sent this email id?
                            if (!in_array($email->email_id, $ignore)) {
                                // check if need senting
                                if ($send_email <= time()) {
                                    $emails[] = $email->email_id;
                                }
                            }
                        }
                        // emails now contains the emails in this series that are due to be sent
                        // in theory this should only be a array of size 1
                        // depends how many emails of day delay 0 there are
                        foreach ($emails as $email_id) {
                            if ($mm_action) {
                                echo ' ' . __('sending EID:', 'ym_mailmanager') . $email_id;
                            }
                            list($subject, $body) = mailmanager_process_hooks($email_id, $row->id, $user_id);
                            mailmanager_send_email($user->email, $subject, $body);
                            mailmanager_log_email_send($user_id, $email_id);
                        }
                    }
                }
            }
        }
    }
}