コード例 #1
0
/**
 * Processes (un)subscription requests to multiple lists
 * @param string $address The email address
 * @param array $list_ids The ids of the lists
 * @param bool $subscribe TRUE if addresss should be subscribed to the lists, FALSE if it should be unsubscribed
 * @return bool TRUE if operation was successful, else FALSE
 */
function gu_subscription_process($address, &$list_ids, $subscribe)
{
    if (!check_email($address)) {
        return gu_error(t("Invalid email address"));
    }
    $succ_list_names = array();
    $fail_list_names = array();
    // For each list we need to load it with all addresses
    foreach ($list_ids as $list_id) {
        $list = gu_list::get($list_id, TRUE);
        // Don't allow subscriptions to private lists
        if ($list->is_private()) {
            $res = FALSE;
        } else {
            if ($subscribe) {
                $res = $list->add($address, TRUE);
            } else {
                $res = $list->remove($address, TRUE);
            }
        }
        if ($res) {
            $succ_list_names[] = $list->get_name();
        } else {
            $fail_list_names[] = $list->get_name();
        }
    }
    // Check if there were any successful
    if (count($succ_list_names) < 1) {
        return FALSE;
    }
    // Work out if we need to send any emails now, and if so create a sender
    if (gu_config::get('list_send_welcome') || gu_config::get('list_send_goodbye') || gu_config::get('list_subscribe_notify') || gu_config::get('list_unsubscribe_notify')) {
        $mailer = new gu_mailer();
        if ($mailer->init()) {
            $subject_prefix = count($succ_list_names) == 1 ? $succ_list_names[0] : gu_config::get('collective_name');
            // Send welcome / goodbye message
            if ($subscribe && gu_config::get('list_send_welcome') || !$subscribe && gu_config::get('list_send_goodbye')) {
                $subject = '[' . $subject_prefix . '] ' . ($subscribe ? t('Subscription') : t('Unsubscription')) . t(' confirmation');
                $action = $subscribe ? t('subscribed to') : t('unsubscribed from');
                $text = t("This is an automated message to confirm that you have been % the following lists:", array($action)) . "\n\n* " . implode("\n* ", $succ_list_names) . "\n\n";
                $text .= t('To change your subscriptions visit: ') . absolute_url('subscribe.php') . '?addr=' . $address . "\n\n";
                $text .= t('Please do not reply to this message. Thank you.');
                $mailer->send_mail($address, $subject, $text);
            }
            // Send admin notifications
            if ($subscribe && gu_config::get('list_subscribe_notify') || !$subscribe && gu_config::get('list_unsubscribe_notify')) {
                $subject = '[' . $subject_prefix . '] ' . ($subscribe ? t('Subscription') : t('Unsubscription')) . t(' notification');
                $action = $subscribe ? t('subscribed to') : t('unsubscribed from');
                $text = t("This is an automated message to notify you that % has been % the following lists:", array($address, $action)) . "\n\n* " . implode("\n* ", $succ_list_names) . "\n\n";
                $mailer->send_admin_mail($subject, $text);
            }
        }
    }
    $action = $subscribe ? t('subscribed to') : t('unsubscribed from');
    return gu_success(t('You have been % lists: <i>%</i>', array($action, implode('</i>, <i>', $succ_list_names))));
}
コード例 #2
0
ファイル: compose.php プロジェクト: inscriptionweb/gutuma
    foreach ($lists as $list) {
        $list_id = (int) get_get_var('list');
        if ($list->get_id() == $list_id) {
            $newsletter->set_recipients($list->get_name());
            break;
        }
    }
}
// Preview the newsletter
$preview_mode = is_post_var('preview_submit');
// Send the newsletter
if (is_post_var('send_submit')) {
    // Saves newsletter to outbox
    if ($newsletter->send_prepare()) {
        $mailer = new gu_mailer();
        if ($mailer->init()) {
            if ($newsletter->send_batch($mailer)) {
                if ($newsletter->is_sending()) {
                    gu_success(t('Newsletter sent to first batch of recipients'));
                } else {
                    gu_success(t('Newsletter sent to all recipients'));
                }
            }
        }
        $newsletter = new gu_newsletter();
        $is_modified = FALSE;
    }
} elseif (is_post_var('attach_submit') && $_FILES['attach_file']['name'] != '') {
    if ($newsletter->store_attachment($_FILES['attach_file']['tmp_name'], $_FILES['attach_file']['name'])) {
        gu_success(t('Attachment <b><i>%</i></b> added', array($_FILES['attach_file']['name'])));
    }
コード例 #3
0
ファイル: cron.php プロジェクト: inscriptionweb/gutuma
 */
/* Gutama plugin package
 * @version 1.6
 * @date	01/10/2013
 * @author	Cyril MAGUIRE
*/
include_once 'inc/gutuma.php';
include_once 'inc/newsletter.php';
include_once 'inc/mailer.php';
// Initialize Gutuma without validation or redirection
gu_init(FALSE, FALSE);
// Get all newsletters in the outbox
$mailbox = gu_newsletter::get_mailbox();
if ($mailbox == FALSE || !isset($mailbox['outbox'])) {
    die(utf8_decode(t('Unable to access mailbox')));
}
// Create mailer
$mailer = new gu_mailer();
if (!$mailer->init()) {
    die(utf8_decode(t('Unable to initialize mailer')));
}
// Start timer
$start_time = time();
// Process outbox
foreach ($mailbox['outbox'] as $newsletter) {
    $newsletter->send_batch($mailer, $start_time);
    // Check batch time limit
    if (time() - $start_time > (int) gu_config::get('batch_time_limit')) {
        break;
    }
}
コード例 #4
0
ファイル: settings.php プロジェクト: inscriptionweb/gutuma
function gu_sender_test()
{
    // Get current settings, which may not have been saved
    $use_smtp = is_post_var('use_smtp');
    $smtp_server = get_post_var('smtp_server');
    $smtp_port = (int) get_post_var('smtp_port');
    $smtp_encryption = get_post_var('smtp_encryption');
    $smtp_username = get_post_var('smtp_username');
    $smtp_password = get_post_var('smtp_password');
    $use_sendmail = is_post_var('use_sendmail');
    $use_phpmail = is_post_var('use_phpmail');
    if (!($use_smtp || $use_sendmail || $use_phpmail)) {
        return gu_error(t('No method of mail transportation has been configured'));
    }
    $test_msg = t('If you have received this email then your settings clearly work!');
    // Test SMTP settings first
    if ($use_smtp) {
        $mailer = new gu_mailer();
        if ($mailer->init(TRUE, $smtp_server, $smtp_port, $smtp_encryption, $smtp_username, $smtp_password, FALSE, FALSE)) {
            if (!$mailer->send_admin_mail('[' . gu_config::get('collective_name') . '] Testing SMTP', $test_msg)) {
                return gu_error(t('Unable to send test message using SMTP'));
            }
        } else {
            return gu_error(t('Unable to initialize mailer with the SMTP settings'));
        }
        $mailer->disconnect();
    }
    // Test Sendmail next
    if ($use_sendmail) {
        $mailer = new gu_mailer();
        if ($mailer->init(FALSE, '', '', '', '', '', FALSE, FALSE)) {
            if (!$mailer->send_admin_mail('[' . gu_config::get('collective_name') . '] Testing Sendmail', $test_msg)) {
                return gu_error(t('Unable to send test message using Sendmail'));
            }
        } else {
            return gu_error(t('Unable to initialize mailer with Sendmail'));
        }
        $mailer->disconnect();
    }
    // Test PHP mail next
    if ($use_phpmail) {
        $mailer = new gu_mailer();
        if ($mailer->init(FALSE, '', '', '', '', '', FALSE, TRUE)) {
            if (!$mailer->send_admin_mail('[' . gu_config::get('collective_name') . '] Testing PHP mail', $test_msg)) {
                return gu_error(t('Unable to send test message using PHP mail'));
            }
        } else {
            return gu_error(t('Unable to initialize mailer with PHP mail'));
        }
        $mailer->disconnect();
    }
    gu_success(t('Test messages sent to <br><i>%</i></b>', array(gu_config::get('admin_email'))));
}