/** * Starts the process of sending an email - either immediately or by adding it to the mail queue. * * @param string Destination email address * @param string Email message subject * @param string Email message body * @param boolean If true, do not use the mail queue and send immediately * @param string Optional name/email to use in 'From' header * @param string Additional headers * @param string Username of person sending the email */ function vbmail($toemail, $subject, $message, $sendnow = false, $from = '', $uheaders = '', $username = '') { if (empty($toemail)) { return false; } global $vbulletin; if (!class_exists('vB_Mail', false)) { require_once(DIR . '/includes/class_mail.php'); } if (!($mail = vB_Mail::fetchLibrary($vbulletin, !$sendnow AND $vbulletin->options['usemailqueue']))) { return false; } if (!$mail->start($toemail, $subject, $message, $from, $uheaders, $username)) { return false; } return $mail->send(); }
/** * The only part of this class which actually sends an email. * Sends mail from the queue. */ function exec_queue() { $vbulletin =& $this->registry; if ($vbulletin->options['usemailqueue'] == 2) { // Lock mailqueue table so that only one process can // send a batch of emails and then delete them $vbulletin->db->lock_tables(array('mailqueue' => 'WRITE')); } $emails = $vbulletin->db->query_read("\n\t\t\tSELECT *\n\t\t\tFROM " . TABLE_PREFIX . "mailqueue\n\t\t\tORDER BY mailqueueid\n\t\t\tLIMIT " . intval($vbulletin->options['emailsendnum'])); $mailqueueids = ''; $newmail = 0; $emailarray = array(); while ($email = $vbulletin->db->fetch_array($emails)) { // count up number of mails about to send $mailqueueids .= ',' . $email['mailqueueid']; $newmail++; $emailarray[] = $email; } if (!empty($mailqueueids)) { // remove mails from queue - to stop duplicates being sent $vbulletin->db->query_write("\n\t\t\t\tDELETE FROM " . TABLE_PREFIX . "mailqueue\n\t\t\t\tWHERE mailqueueid IN (0 {$mailqueueids})\n\t\t\t"); if ($vbulletin->options['usemailqueue'] == 2) { $vbulletin->db->unlock_tables(); } $prototype = vB_Mail::fetchLibrary($vbulletin); foreach ($emailarray as $index => $email) { // send those mails $mail = clone $prototype; $mail->quick_set($email['toemail'], $email['subject'], $email['message'], $email['header'], $email['fromemail']); $mail->send(); } $newmail = 'data - ' . intval($newmail); } else { if ($vbulletin->options['usemailqueue'] == 2) { $vbulletin->db->unlock_tables(); } $newmail = 0; } // update number of mails remaining $vbulletin->db->query_write("\n\t\t\tUPDATE " . TABLE_PREFIX . "datastore SET\n\t\t\t\tdata = " . $newmail . ",\n\t\t\t\tdata = IF(data < 0, 0, data)\n\t\t\tWHERE title = 'mailqueue'\n\t\t"); // if we're using a alternate datastore, we need to give it an integer value // this may not be atomic if (method_exists($vbulletin->datastore, 'build')) { $mailqueue_db = $vbulletin->db->query_first("\n\t\t\t\tSELECT data\n\t\t\t\tFROM " . TABLE_PREFIX . "datastore\n\t\t\t\tWHERE title = 'mailqueue'\n\t\t\t"); $vbulletin->datastore->build('mailqueue', intval($mailqueue_db['data'])); } }
print_table_header($vbphrase['pertinent_php_settings']); print_label_row('SMTP:', iif($SMTP = @ini_get('SMTP'), $SMTP, '<i>' . $vbphrase['none'] . '</i>')); print_label_row('sendmail_from:', iif($sendmail_from = @ini_get('sendmail_from'), $sendmail_from, '<i>' . $vbphrase['none'] . '</i>')); print_label_row('sendmail_path:', iif($sendmail_path = @ini_get('sendmail_path'), $sendmail_path, '<i>' . $vbphrase['none'] . '</i>')); } print_table_footer(); $emailaddress = $vbulletin->GPC['emailaddress']; if (empty($emailaddress)) { print_diagnostic_test_result(0, $vbphrase['please_complete_required_fields']); } if (!is_valid_email($emailaddress)) { print_diagnostic_test_result(0, $vbphrase['invalid_email_specified']); } $subject = $vbulletin->options['needfromemail'] ? $vbphrase['vbulletin_email_test_withf'] : $vbphrase['vbulletin_email_test']; $message = construct_phrase($vbphrase['vbulletin_email_test_msg'], $vbulletin->options['bbtitle']); $mail = vB_Mail::fetchLibrary(); $mail->setDebug(true); $mail->start($emailaddress, $subject, $message, $vbulletin->options['webmasteremail']); // error handling @ini_set('display_errors', true); if (strpos(@ini_get('disable_functions'), 'ob_start') !== false) { // alternate method in case OB is disabled; probably not as fool proof @ini_set('track_errors', true); $oldlevel = error_reporting(0); } else { ob_start(); } $mailreturn = $mail->send(true); if (strpos(@ini_get('disable_functions'), 'ob_start') !== false) { error_reporting($oldlevel); $errors = $php_errormsg;
print_diagnostic_test_result(0, $vbphrase['please_complete_required_fields']); } if (!is_valid_email($emailaddress)) { print_diagnostic_test_result(0, $vbphrase['invalid_email_specified']); } $subject = ($vbulletin->options['needfromemail'] ? $vbphrase['vbulletin_email_test_withf'] : $vbphrase['vbulletin_email_test']); $message = construct_phrase($vbphrase['vbulletin_email_test_msg'], $vbulletin->options['bbtitle']); if (!class_exists('vB_Mail', false)) { require_once(DIR . '/includes/class_mail.php'); } $mail = vB_Mail::fetchLibrary($vbulletin); $mail->set_debug(true); $mail->start($emailaddress, $subject, $message, $vbulletin->options['webmasteremail']); // error handling @ini_set('display_errors', true); if (strpos(@ini_get('disable_functions'), 'ob_start') !== false) { // alternate method in case OB is disabled; probably not as fool proof @ini_set('track_errors', true); $oldlevel = error_reporting(0); } else { ob_start(); }
/** * The only part of this class which actually sends an email. * Sends mail from the queue. */ public function execQueue() { $vboptions = vB::getDatastore()->getValue('options'); if ($vboptions['usemailqueue'] == 2) { // Lock mailqueue table so that only one process can // send a batch of emails and then delete them vB::getDbAssertor()->assertQuery('mailqueue_locktable'); } $emails = vB::getDbAssertor()->getRows('mailqueue_fetch', array('limit' => intval($vboptions['emailsendnum']))); $mailqueueids = array(); $newmail = 0; $emailarray = array(); foreach ($emails as $email) { // count up number of mails about to send $mailqueueids[] = $email['mailqueueid']; $newmail++; $emailarray[] = $email; } if (!empty($mailqueueids)) { // remove mails from queue - to stop duplicates being sent vB::getDbAssertor()->delete('mailqueue', array('mailqueueid' => $mailqueueids)); if ($vboptions['usemailqueue'] == 2) { vB::getDbAssertor()->assertQuery('unlock_tables'); } $prototype = vB_Mail::fetchLibrary(); foreach ($emailarray as $email) { // send those mails $mail = clone $prototype; $mail->quickSet($email['toemail'], $email['subject'], $email['message'], $email['header'], $email['fromemail']); $mail->send(); } $newmail = 'data - ' . intval($newmail); } else { if ($vboptions['usemailqueue'] == 2) { vB::getDbAssertor()->assertQuery('unlock_tables'); } $newmail = 0; } // update number of mails remaining vB::getDbAssertor()->assertQuery('mailqueue_updatecount2', array('newmail' => $newmail)); // if we're using a alternate datastore, we need to give it an integer value // this may not be atomic $mailqueue_db = vB::getDbAssertor()->getRow('datastore', array('title' => 'mailqueue')); vB::getDatastore()->build('mailqueue', intval($mailqueue_db['data'])); }