Esempio n. 1
0
                if (count($existing_subscription_array) == 0) {
                    // The submit email address doesn't exist in the db --- start
                    // Perform a look up in the user db of coppermine to see if the email address belongs to a registered user who hasn't subscribed so far
                    // Perform a category check
                    // Write the registration into the database
                    // Send the verification email
                    // Tell the subscriber to check his email
                } else {
                    // The submit email address doesn't exist in the db --- end // There already is a record for the submit email address --- start
                    if ($existing_subscription_array['user_id'] != 0) {
                        $registration_message = '<div class="cpg_message_error">' . sprintf($lang_plugin_newsletter['email_address_belongs_to_registered_subscriber'], '<a href="login.php?referer=index.php%3Ffile%3Dnewsletter%2Fsubscribe">', '</a>') . '</div>';
                    } else {
                        $registration_message = sprintf($lang_plugin_newsletter['subscription_exists_for_email_address'], $submit_email_address, '<a href="index.php?file=newsletter/subscribe&amp;action=mailsent">', '</a>');
                        $message_plain = $lang_plugin_newsletter['click_to_edit_subscription'];
                        $message_plain .= 'Edit later';
                        $message_html = newsletter_text2html($lang_plugin_newsletter['newsletter_subscription_authentification'], $CONFIG['plugin_newsletter_salutation_for_guests'], $message_plain);
                        cpg_mail($submit_email_address, $lang_plugin_newsletter['newsletter_subscription_authentification'], $message_html, 'text/plain', $CONFIG['plugin_newsletter_from_name'], $CONFIG['plugin_newsletter_from_email'], $message_plain);
                        if ($CONFIG['log_mode'] != CPG_NO_LOGGING) {
                            log_write("Newsletter plugin: {$submit_email_address} requested an authentification email from the subscribe page", CPG_MAIL_LOG);
                        }
                    }
                }
                // There already is a record for the submit email address --- end
                // The email Address is valid --- end
            } else {
                $subscriber_email_warning = '<div class="cpg_message_validation">' . $lang_plugin_newsletter['email_address_invalid'] . '</div>';
            }
        }
    }
    // guest --- end
}
Esempio n. 2
0
function newsletter_mailqueue()
{
    if (defined('CPG_PLUGIN_NEWSLETTER_MAILQUEUE')) {
        return;
    }
    global $CONFIG, $lang_plugin_newsletter, $newsletter_icon_array;
    require_once 'include/mailer.inc.php';
    $output_array = array();
    $query = "SELECT * \n               FROM {$CONFIG['TABLE_PREFIX']}plugin_newsletter_queue \n               AS queue \n               INNER JOIN {$CONFIG['TABLE_PREFIX']}plugin_newsletter_mailings \n               AS mailings\n               ON mailings.mailing_id = queue.mailing_id\n               INNER JOIN {$CONFIG['TABLE_PREFIX']}plugin_newsletter_subscriptions \n               AS subscriptions\n               ON subscriptions.subscriber_id = queue.subscriber_id\n               WHERE queue.attempts <= {$CONFIG['plugin_newsletter_mails_per_page']}\n               ORDER BY queue.attempts,queue.time \n               LIMIT {$CONFIG['plugin_newsletter_mails_per_page']}";
    $result = cpg_db_query($query);
    $mailqueue_array = cpg_db_fetch_rowset($result);
    mysql_free_result($result);
    foreach ($mailqueue_array as $mailqueue) {
        if ($mailqueue['user_id'] == '') {
            // Guest
            $salutation = $CONFIG['plugin_newsletter_salutation_for_guests'];
        } else {
            // Registered user
            $salutation = str_replace('{USERNAME}', $mailqueue['subscriber_name'], $mailqueue['salutation']);
        }
        $mailing_message_plain = $salutation . $LINEBREAK . $mailqueue['body'] . $LINEBREAK . $LINEBREAK;
        // Add the unsubscribe link at the bottom
        $mailing_message_plain .= $lang_plugin_newsletter['unsubscribe_text'];
        $mailing_message_plain .= ' ' . $CONFIG['site_url'] . 'index.php?file=newsletter/unsubscribe';
        $mailing_message_html = newsletter_text2html($mailqueue['subject'], $salutation, $mailqueue['body']);
        if (!cpg_mail($mailqueue['subscriber_email'], $mailqueue['subject'], $mailing_message_html, 'text/plain', $CONFIG['plugin_newsletter_from_name'], $CONFIG['plugin_newsletter_from_email'], $mailing_message_plain)) {
            // sending the email has failed --- start
            $output_array[] = '<span class="important">' . $newsletter_icon_array['failure'] . sprintf($lang_plugin_newsletter['sending_email_failed'], '<a href="index.php?file=newsletter/archive&amp;mailing="' . $mailqueue['mailing_id'] . '">' . $mailqueue['subject'] . '</a>', '<a href="index.php?file=newsletter/subscribe&amp;subscriber=' . $mailqueue['subscriber_id'] . '">' . $mailqueue['subscriber_email'] . '</a>', $mailqueue['attempts'] + 1) . '</span>';
            cpg_db_query("UPDATE {$CONFIG['TABLE_PREFIX']}plugin_newsletter_queue SET attempts = attempts + 1 WHERE queue_id={$mailqueue['queue_id']}");
            if ($CONFIG['log_mode'] != CPG_NO_LOGGING) {
                log_write("Sending an email using the newsletter plugin failed (recipient email: {$mailqueue['subscriber_email']}, subscriber ID: {$mailqueue['subscriber_id']}, Mailing ID: {$mailqueue['mailing_id']}, Attempt: {$mailqueue['attempts']})", CPG_MAIL_LOG);
            }
        } else {
            // sending the email has failed --- end // sending the email has been successfull --- start
            $output_array[] = $newsletter_icon_array['success'] . sprintf($lang_plugin_newsletter['sending_email_succeeded'], '<a href="index.php?file=newsletter/archive&amp;mailing="' . $mailqueue['mailing_id'] . '>' . $mailqueue['subject'] . '</a>', '<a href="index.php?file=newsletter/subscribe&amp;subscriber=' . $mailqueue['subscriber_id'] . '">' . $mailqueue['subscriber_email'] . '</a>');
            $processed_records_counter++;
            cpg_db_query("DELETE FROM {$CONFIG['TABLE_PREFIX']}plugin_newsletter_queue WHERE queue_id={$mailqueue['queue_id']}");
            if ($CONFIG['log_mode'] == CPG_LOG_ALL) {
                log_write("Sending email from newsletter plugin successful (recipient email: {$mailqueue['subscriber_email']}, subscriber ID: {$mailqueue['subscriber_id']}, Mailing ID: {$mailqueue['mailing_id']})", CPG_MAIL_LOG);
            }
        }
        // sending the email has been successfull --- end
    }
    define('CPG_PLUGIN_NEWSLETTER_MAILQUEUE', true);
    return $output_array;
}