예제 #1
0
파일: mail.php 프로젝트: notzen/e107
function sendemail($send_to, $subject, $message, $to_name, $send_from = '', $from_name = '', $attachments = '', $Cc = '', $Bcc = '', $returnpath = '', $returnreceipt = '', $inline = '')
{
    global $mailheader_e107id;
    $overrides = array();
    // TODO: Find a way of doing this which doesn't use a global (or just ditch sendemail() )
    // ----- Mail pref. template override for parked domains, site mirrors or dynamic values
    global $EMAIL_OVERRIDES;
    if (isset($EMAIL_OVERRIDES) && is_array($EMAIL_OVERRIDES)) {
        $overrides =& $EMAIL_OVERRIDES;
        // These can override many of the email-related prefs
        if (isset($EMAIL_OVERRIDES['bouncepath'])) {
            $returnpath = $EMAIL_OVERRIDES['bouncepath'];
        }
        if (isset($EMAIL_OVERRIDES['returnreceipt'])) {
            $returnreceipt = $EMAIL_OVERRIDES['returnreceipt'];
        }
    }
    // Create a mailer object of the correct type (which auto-fills in sending method, server details)
    $mail = new e107Email($overrides);
    if (varsettrue($mailheader_e107id)) {
        $mail->AddCustomHeader("X-e107-id: {$mailheader_e107id}");
    }
    $mail->legacyBody = TRUE;
    // Need to handle plain text email conversion to HTML
    $mail->makeBody($message);
    // Add body, with conversion if required
    if ($Cc) {
        $mail->AddAddressList('cc', $Cc);
    }
    if ($Bcc) {
        $mail->AddAddressList('bcc', $Bcc);
    }
    if (trim($send_from)) {
        $mail->SetFrom($send_from, $from_name);
        // These have already been defaulted to sitewide options, so no need to set again if blank
    }
    $mail->Subject = $subject;
    $mail->attach($attachments);
    // Add embedded images (should be auto-handled now)
    if ($inline) {
        $mail->addInlineImages($inline);
    }
    // Passed parameter overrides any system default for bounce - but should this be 'ReplyTo' address instead?
    //  if (varsettrue($returnpath)) $mail->Sender = $AddReplyToAddresses($returnpath,'');
    if (varsettrue($returnpath)) {
        $mail->Sender = $returnpath;
    }
    if (varsettrue($returnreceipt)) {
        $mail->ConfirmReadingTo($returnreceipt);
    }
    if ($mail->sendEmail($send_to, $to_name) === TRUE) {
        // Success
        return TRUE;
    }
    // Error info already logged
    return FALSE;
}
예제 #2
0
파일: signup.php 프로젝트: notzen/e107
 $adviseLoginName = '';
 if (varsettrue($pref['predefinedLoginName']) && (int) $pref['allowEmailLogin'] === 0) {
     $adviseLoginName = LAN_SIGNUP_65 . ': ' . $allData['data']['user_loginname'] . '<br />' . LAN_SIGNUP_66 . '<br />';
 }
 if ($pref['user_reg_veri']) {
     // Verification required (may be by email or by admin)
     // ========== Send Email =========>
     if ($pref['user_reg_veri'] != 2 && $allData['data']['user_email']) {
         $allData['data']['user_id'] = $nid;
         // User ID
         $allData['data']['user_password'] = $savePassword;
         // Might need to send plaintext password in the email
         $eml = render_email($allData['data']);
         $eml['e107_header'] = $eml['userid'];
         require_once e_HANDLER . 'mail.php';
         $mailer = new e107Email();
         // FIX - sendEmail returns TRUE or error message...
         if (true !== $mailer->sendEmail($allData['data']['user_email'], $allData['data']['user_name'], $eml, FALSE)) {
             $error_message = LAN_SIGNUP_42;
             // There was a problem, the registration mail was not sent, please contact the website administrator.
         }
         unset($allData['data']['user_password']);
     }
     $e_event->trigger('usersup', $_POST);
     // Old trigger - send everything in the template, including extended fields.
     // FIXME - undocummented feature - userpartial trigger (better trigger name?)
     $e_event->trigger('userpartial', array_merge($allData['data'], $eufVals['data']));
     // New trigger - send everything in the template, including extended fields.
     require_once HEADERF;
     $after_signup = render_after_signup($error_message);
     $ns->tablerender($after_signup['caption'], $after_signup['text']);
예제 #3
0
 /**
  * Call to send next email from selection
  * 
  * @return Returns TRUE if successful, FALSE on fail (or no more to go)
  */
 public function sendNextEmail()
 {
     $counterList = array('mail_source_id', 'mail_togo_count', 'mail_sent_count', 'mail_fail_count', 'mail_start_send');
     if (($email = $this->getNextEmail()) === FALSE) {
         return FALSE;
     }
     if (count($this->currentBatchInfo)) {
         //print_a($this->currentBatchInfo);
         if ($this->currentBatchInfo['mail_source_id'] != $email['mail_source_id']) {
             // New email body etc started
             //echo "New email body: {$this->currentBatchInfo['mail_source_id']} != {$email['mail_source_id']}<br />";
             $this->currentBatchInfo = array();
             // New source email - clear stored info
             $this->currentMailBody = '';
             // ...and clear cache for message body
         }
     }
     if (count($this->currentBatchInfo) == 0) {
         //echo "First email of batch: {$email['mail_source_id']}<br />";
         foreach ($counterList as $k) {
             $this->currentBatchInfo[$k] = $email[$k];
             // This copies across all the counts
         }
     }
     if ($this->currentBatchInfo['mail_sent_count'] > 0 || $this->currentBatchInfo['mail_fail_count'] > 0) {
         // Only send these on first email - otherwise someone could get inundated!
         unset($email['mail_copy_to']);
         unset($email['mail_bcopy_to']);
     }
     $targetData = array();
     // Arrays for updated data
     $this->checkMailer();
     // Make sure we have a mailer object to play with
     if ($this->currentBatchInfo['mail_start_send'] == 0) {
         $this->currentBatchInfo['mail_start_send'] = time();
         // Log when we started processing this email
     }
     if (!$this->currentMailBody) {
         $this->currentMailBody = $this->makeEmailBody($email['mail_body'], $email['mail_send_style'], varset($email['mail_include_images'], FALSE));
     }
     // Do any substitutions
     $search = array();
     $replace = array();
     foreach ($email['mail_target_info'] as $k => $v) {
         $search[] = '|' . $k . '|';
         $replace[] = $v;
     }
     $email['mail_body'] = str_replace($search, $replace, $this->currentMailBody);
     $email['send_html'] = $email['mail_send_style'] != 'textonly';
     // Set up any extra mailer parameters that need it
     if (!vartrue($email['e107_header'])) {
         $temp = intval($email['mail_recipient_id']) . '/' . intval($email['mail_source_id']) . '/' . intval($email['mail_target_id']) . '/';
         $email['e107_header'] = $temp . md5($temp);
         // Set up an ID
     }
     if (isset($email['mail_attach']) && (trim($email['mail_attach']) || is_array($email['mail_attach']))) {
         $downDir = realpath(e_ROOT . $this->e107->getFolder('downloads'));
         if (is_array($email['mail_attach'])) {
             foreach ($email['mail_attach'] as $k => $v) {
                 $email['mail_attach'][$k] = $downDir . $v;
             }
         } else {
             $email['mail_attach'] = $downDir . $email['mail_attach'];
         }
     }
     //		print_a($email);
     // Try and send
     $result = $this->mailer->sendEmail($email['mail_recipient_email'], $email['mail_recipient_name'], $email, TRUE);
     //		return;			// ************************************************** Temporarily stop DB being updated when line active *****************************
     $this->checkDB(2);
     // Make sure DB object created
     // Now update email status in DB. We just create new arrays of changed data
     if ($result === TRUE) {
         // Success!
         $targetData['mail_status'] = MAIL_STATUS_SENT;
         $targetData['mail_send_date'] = time();
         $this->currentBatchInfo['mail_togo_count']--;
         $this->currentBatchInfo['mail_sent_count']++;
     } else {
         // Failure
         // If fail and still retries, downgrade priority
         if ($targetData['mail_status'] > MAIL_STATUS_PENDING) {
             $targetData['mail_status'] = max($targetData['mail_status'] - 1, MAIL_STATUS_PENDING);
             // One off retry count
             $targetData['mail_e107_priority'] = max($email['mail_e107_priority'] - 1, 1);
             // Downgrade priority to avoid clag-ups
         } else {
             $targetData['mail_status'] = MAIL_STATUS_FAILED;
             $this->currentBatchInfo['mail_togo_count'] = max($this->currentBatchInfo['mail_togo_count'] - 1, 0);
             $this->currentBatchInfo['mail_fail_count']++;
             $targetData['mail_send_date'] = time();
         }
     }
     if (isset($this->currentBatchInfo['mail_togo_count']) && $this->currentBatchInfo['mail_togo_count'] == 0) {
         $this->currentBatchInfo['mail_end_send'] = time();
         $this->currentBatchInfo['mail_content_status'] = MAIL_STATUS_SENT;
     }
     // Update DB record, mail record with status (if changed). Must use different sql object
     if (count($targetData)) {
         //print_a($targetData);
         $this->db2->db_Update('mail_recipients', array('data' => $targetData, '_FIELD_TYPES' => $this->dbTypes['mail_recipients'], 'WHERE' => '`mail_target_id` = ' . intval($email['mail_target_id'])));
     }
     if (count($this->currentBatchInfo)) {
         //print_a($this->currentBatchInfo);
         $this->db2->db_Update('mail_content', array('data' => $this->currentBatchInfo, '_FIELD_TYPES' => $this->dbTypes['mail_content'], 'WHERE' => '`mail_source_id` = ' . intval($email['mail_source_id'])));
     }
     if ($this->currentBatchInfo['mail_togo_count'] == 0 && $email['mail_notify_complete'] > 0) {
         // Need to notify completion
         $email = array_merge($email, $this->currentBatchInfo);
         // This should ensure the counters are up to date
         $mailInfo = LAN_MAILOUT_247 . '<br />' . LAN_MAILOUT_135 . ': ' . $email['mail_title'] . '<br />' . LAN_MAILOUT_248 . $this->statusToText($email['mail_content_status']) . '<br />';
         $mailInfo .= '<br />' . LAN_MAILOUT_249 . '<br />';
         foreach ($this->mailCountFields as $f => $t) {
             $mailInfo .= $t . ' => ' . $email[$f] . '<br />';
         }
         $mailInfo .= LAN_MAILOUT_250;
         $message = array('mail_subject' => LAN_MAILOUT_244 . $email['mail_subject'], 'mail_body' => $mailInfo . '<br />');
         if ($email['mail_notify_complete'] & 1) {
             // Notify email initiator
             if ($this->db2->db_Select('user', 'user_name, user_email', '`user_id`=' . intval($email['mail_creator']))) {
                 $row = $this->db2->db_Fetch(MYSQL_ASSOC);
                 require_once e_HANDLER . 'mail.php';
                 $mailer = new e107Email();
                 $mailer->sendEmail($row['user_name'], $row['user_email'], $message, FALSE);
             }
         }
         if ($email['mail_notify_complete'] & 2) {
             // Do e107 notify
             require_once e_HANDLER . "notify_class.php";
             notify_maildone($message);
         }
         e107::getEvent()->trigger('maildone', $email);
     }
     return $result;
 }