function proces_subissions()
 {
     if (wp_verify_nonce($_POST['wpem_send_mail_nonce'], 'wpem_send_mail')) {
         $mail = EM_Mailer::send_mail($_REQUEST['mail']);
         if (is_integer($mail)) {
             $location = add_query_arg('message', 1, admin_url('admin.php?page=wpem_mail&recepients=' . absint($mail)));
             wp_redirect($location);
         }
         $this->submit_results = $mail;
     }
 }
Ejemplo n.º 2
0
<?php

if ($_SERVER['SCRIPT_FILENAME'] == __FILE__) {
    die('Access denied.');
}
$errors = isset($mail['errors']) ? $mail['errors'] : null;
if (!is_wp_error($errors)) {
    $errors = new WP_Error();
}
$data_sources = EM_Mailer::get_data_sources();
if (isset($_REQUEST['data_source']) && array_key_exists($_REQUEST['data_source'], $data_sources)) {
    $email_source = $_REQUEST['data_source'];
} elseif (isset($mail['source']['id'])) {
    $email_source = $mail['source']['id'];
} else {
    $email_source = 'wp';
}
?>


<div class="wrap">
    <div id="icon-options-general" class="icon32"><br /></div>

    <?php 
wpem_mail_tabs();
if (isset($_REQUEST['message']) && isset($_REQUEST['recepients'])) {
    $recepients = $_REQUEST['recepients'];
    ?>
        <div id="message" class="updated"><p><?php 
    echo sprintf(__('The email was sent to %s recepients', 'wpem'), $recepients);
    ?>
Ejemplo n.º 3
0
 /**
  * Send an email and log errors in this object
  * @param string $subject
  * @param string $body
  * @param string $email
  * @return string
  */
 function email_send($subject, $body, $email)
 {
     global $EM_Mailer;
     if (!empty($subject)) {
         if (!is_object($EM_Mailer)) {
             $EM_Mailer = new EM_Mailer();
         }
         if (!$EM_Mailer->send($subject, $body, $email)) {
             if (is_array($EM_Mailer->errors)) {
                 foreach ($EM_Mailer->errors as $error) {
                     $this->errors[] = $error;
                 }
             } else {
                 $this->errors[] = $EM_Mailer->errors;
             }
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 public static function process_queue()
 {
     //check that this isn't doing cron already - if this is MultiSite Global, then we place a lock at Network level
     $doing_emails = EM_MS_GLOBAL ? get_site_option('em_cron_doing_emails') : get_option('em_cron_doing_emails');
     if ($doing_emails) {
         //if process has been running for over 15 minutes or 900 seconds (e.g. likely due to a php error or timeout), let it proceed
         if ($doing_emails > time() - 900) {
             return false;
         }
     }
     EM_MS_GLOBAL ? update_site_option('em_cron_doing_emails', time()) : update_option('em_cron_doing_emails', time());
     //init phpmailer
     global $EM_Mailer, $wpdb;
     if (!is_object($EM_Mailer)) {
         $EM_Mailer = new EM_Mailer();
     }
     //get queue
     $limit = get_option('dbem_cron_emails_limit', 100);
     $count = 0;
     $sql = "SELECT * FROM " . EM_EMAIL_QUEUE_TABLE . " ORDER BY queue_id  ASC LIMIT 100";
     $results = $wpdb->get_results($sql);
     //loop through results of query whilst results exist
     while ($wpdb->num_rows > 0) {
         //go through current results set
         foreach ($results as $email) {
             //if we reach a limit (provided limit is > 0, remove lock and exit this function
             if ($count >= $limit && $limit > 0) {
                 EM_MS_GLOBAL ? update_site_option('em_cron_doing_emails', 0) : update_option('em_cron_doing_emails', 0);
                 return true;
             }
             //send email, immediately delete after from queue
             if ($EM_Mailer->send($email->subject, $email->body, $email->email, unserialize($email->attachment))) {
                 $wpdb->query("DELETE FROM " . EM_EMAIL_QUEUE_TABLE . ' WHERE queue_id =' . $email->queue_id);
             }
             //add to the count and move onto next email
             $count++;
         }
         //if we haven't reached a limit, load up new results
         $results = $wpdb->get_results($sql);
     }
     //remove the lock on this cron
     EM_MS_GLOBAL ? update_site_option('em_cron_doing_emails', 0) : update_option('em_cron_doing_emails', 0);
 }
 public function validate_inputs($post)
 {
     $post = apply_filters('wpem_pre_validate_schedule', $post);
     $errors = new WP_Error();
     if (!absint($post['id'])) {
         $errors->add('schedule_id', __('invalid schedule.', 'wpem'));
     }
     $data_sources = EM_Mailer::get_data_sources();
     if (!isset($post['source']['id']) || !array_key_exists($post['source']['id'], $data_sources)) {
         $errors->add('email_source', __('Invalid value for Emaill source given', 'wpem'));
     }
     /* if($post['source']['id']=='wp'){
     
                   }else{
     
                   } */
     if (!in_array($post['mail_format'], array('html', 'plaintext'))) {
         $errors->add('mail_format', __('Unsupported mail format', 'wpem'));
     }
     if (empty($post['from_name'])) {
         $errors->add('from_name', __('From Name should not be empty', 'wpem'));
     } else {
         $post['from_name'] = sanitize_text_field($post['from_name']);
     }
     if (!is_email($post['from_email'])) {
         $errors->add('from_email', __('invalid email', 'wpem'));
     } else {
         $post['from_email'] = sanitize_email($post['from_email']);
     }
     $start_date = $post['start_date'];
     if (!preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2})#', $start_date, $matches)) {
         $errors->add('start_date', __('Invalid Start Date', 'wpem'));
     }
     if (!in_array($post['frequency'], array('Once', 'Daily', 'Weekly', 'Monthly', 'Yearly'))) {
         $errors->add('frequency', __('Invalid Frequency', 'wpem'));
     }
     $end_date = $post['end_date'];
     if (!preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2})#', $end_date, $matches)) {
         $errors->add('end_date', __('Invalid End Date', 'wpem'));
     }
     if (!intval($post['template'])) {
         $errors->add('template', __('Invalid template', 'wpem'));
     }
     if (empty($post['title'])) {
         $errors->add('title', __('Title cannot be empty.', 'wpem'));
     } else {
         $post['title'] = sanitize_text_field($post['title']);
     }
     if (empty($post['body'])) {
         $errors->add('body', __('Notification body cannot be empty.', 'wpem'));
     } else {
         $post['body'] = wp_unslash($post['body']);
     }
     if (!empty($post['attachments'])) {
         $post['attachments'] = wpem_sanitize_attachments($post['attachments']);
     }
     foreach ($post as $key => $value) {
         if (!in_array($key, apply_filters('wpem_allowed_mail_keys', array('id', 'source', 'mail_format', 'from_name', 'from_email', 'start_date', 'frequency', 'end_date', 'template', 'title', 'body', 'attachments')))) {
             unset($post[$key]);
         }
     }
     $post['errors'] = $errors;
     return apply_filters('wpem_validate_schedule', $post);
 }
Ejemplo n.º 6
0
 * Check requirements and load main class
 * The main program needs to be in a separate file that only gets loaded if the plugin requirements are met. Otherwise older PHP installations could crash when trying to parse it.
 */
if (wpem_requirements_met()) {
    require_once __DIR__ . '/includes/functions.php';
    require_once __DIR__ . '/modules/single-mail.php';
    require_once __DIR__ . '/classes/wpem-module.php';
    require_once __DIR__ . '/classes/email-manager.php';
    require_once __DIR__ . '/includes/admin-notice-helper/admin-notice-helper.php';
    require_once __DIR__ . '/classes/wpem-custom-post-type.php';
    require_once __DIR__ . '/classes/wpem-template-class.php';
    require_once __DIR__ . '/classes/wpem-settings.php';
    require_once __DIR__ . '/classes/wpem-cron.php';
    require_once __DIR__ . '/classes/wpem-instance-class.php';
    require_once __DIR__ . '/classes/wpem-schedules-class.php';
    require_once __DIR__ . '/classes/wpem-schedules-table-class.php';
    require_once __DIR__ . '/classes/wpem-notifications-class.php';
    require_once __DIR__ . '/classes/wpem-send-mail-class.php';
    if (class_exists('Email_Manager')) {
        $GLOBALS['wpem'] = Email_Manager::get_instance();
        $EM_Mailer = EM_Mailer::get_instance();
        register_activation_hook(__FILE__, array($GLOBALS['wpem'], 'activate'));
        register_deactivation_hook(__FILE__, array($GLOBALS['wpem'], 'deactivate'));
    }
} else {
    add_action('admin_notices', 'wpem_requirements_error');
}
function WPEM()
{
    return $GLOBALS['wpem'];
}
Ejemplo n.º 7
0
 case 'test_mail':
     $ms = WPEM()->modules['settings']->settings['mail'];
     $mail['source'] = array('id' => 'sm');
     $mail['mail_format'] = $_REQUEST['m_format'];
     $mail['from_email'] = !empty($ms['from_sender_email']) ? $ms['from_sender_email'] : get_option('admin_email');
     $mail['from_name'] = !empty($ms['from_sender_name']) ? $ms['from_sender_name'] : get_bloginfo('name');
     $mail['title'] = __('Test Mail', 'wpem');
     $mail['body'] = $_REQUEST['m_body'];
     $mail['template'] = $_REQUEST['temp_id'];
     $current_user = get_user_by('id', get_current_user_id());
     $full_names = !empty($current_user->first_name) || !empty($current_user->last_name) ? ucfirst($current_user->first_name) . ' ' . ucfirst($current_user->last_name) : $current_user->display_name;
     $mail['to_email'] = $current_user->user_email;
     $mail['to_name'] = $full_names;
     $json = array();
     try {
         $mail = EM_Mailer::send_mail($mail);
         if (is_integer($mail)) {
             global $user_email;
             $json['sent'] = sprintf(__('Test email sent to %s', 'wpem'), $user_email);
         } else {
             if (isset($mail['errors'])) {
                 if ($errmsg = $mail['errors']->get_error_message('body')) {
                     $json['error'] = $errmsg;
                 } else {
                     print_r($mail['errors']);
                 }
             }
         }
         echo json_encode($json);
     } catch (Exception $e) {
         ?>
Ejemplo n.º 8
0
 function process_queue()
 {
     //init phpmailer
     global $EM_Mailer, $wpdb;
     if (!is_object($EM_Mailer)) {
         $EM_Mailer = new EM_Mailer();
     }
     add_action('em_mailer', array('EM_Emails', 'em_mailer_mod'), 10, 1);
     add_action('em_mailer_sent', array('EM_Emails', 'em_mailer_mod_cleanup'), 10, 1);
     //get queue
     $limit = get_option('emp_cron_emails_limit', 100);
     $results = $wpdb->get_results("SELECT * FROM " . EM_EMAIL_QUEUE_TABLE . " ORDER BY queue_id  ASC LIMIT {$limit}");
     $ids_to_delete = array();
     foreach ($results as $email) {
         $ids_to_delete[] = $email->queue_id;
         $EM_Mailer->send($email->subject, $email->body, $email->email, unserialize($email->attachment));
     }
     //cleanup
     if (count($ids_to_delete) > 0) {
         $wpdb->query("DELETE FROM " . EM_EMAIL_QUEUE_TABLE . ' WHERE queue_id IN (' . implode(',', $ids_to_delete) . ')');
     }
     remove_action('em_mailer', array('EM_Emails', 'em_mailer_mod'), 10, 1);
     remove_action('em_mailer_sent', array('EM_Emails', 'em_mailer_mod_cleanup'), 10, 1);
 }