function sendNotification($options = array()) { global $LANG; $mmail = new self(); $mmail->AddCustomHeader("Auto-Submitted: auto-generated"); $mmail->SetFrom($options['from'], $options['fromname']); if ($options['replyto']) { $mmail->AddReplyTo($options['replyto'], $options['replytoname']); } $mmail->Subject = $options['subject']; if (empty($options['content_html'])) { $mmail->isHTML(false); $mmail->Body = $options['content_text']; } else { $mmail->isHTML(true); $mmail->Body = $options['content_html']; $mmail->AltBody = $options['content_text']; } $mmail->AddAddress($options['to'], $options['toname']); $mmail->MessageID = "<GLPI-" . $options["items_id"] . "." . time() . "." . rand() . "@" . php_uname('n') . ">"; $messageerror = $LANG['mailing'][47]; if (!$mmail->Send()) { $senderror = true; addMessageAfterRedirect($messageerror . "<br>" . $mmail->ErrorInfo, true); } else { logInFile("mail", $LANG['tracking'][38] . " " . $options['to'] . " : " . $options['subject'] . "\n"); } $mmail->ClearAddresses(); return true; }
/** * Dispatch (send) email that was queued. */ static function dispatchQueue(Vtiger_Mailer_Listener $listener = null) { global $adb; if (!Vtiger_Utils::CheckTable('vtiger_mailer_queue')) { return; } $mailer = new self(); $queue = $adb->pquery('SELECT * FROM vtiger_mailer_queue WHERE failed != ?', array(1)); if ($adb->num_rows($queue)) { for ($index = 0; $index < $adb->num_rows($queue); ++$index) { $mailer->reinitialize(); $queue_record = $adb->fetch_array($queue, $index); $queueid = $queue_record['id']; $relcrmid = $queue_record['relcrmid']; $mailer->From = $queue_record['fromemail']; $mailer->From = $queue_record['fromname']; $mailer->Subject = $queue_record['subject']; $mailer->Body = decode_html($queue_record['body']); $mailer->Mailer = $queue_record['mailer']; $mailer->ContentType = $queue_record['content_type']; $emails = $adb->pquery('SELECT * FROM vtiger_mailer_queueinfo WHERE id=?', array($queueid)); for ($eidx = 0; $eidx < $adb->num_rows($emails); ++$eidx) { $email_record = $adb->fetch_array($emails, $eidx); if ($email_record[type] == 'TO') { $mailer->AddAddress($email_record[email], $email_record[name]); } else { if ($email_record[type] == 'CC') { $mailer->AddCC($email_record[email], $email_record[name]); } else { if ($email_record[type] == 'BCC') { $mailer->AddBCC($email_record[email], $email_record[name]); } else { if ($email_record[type] == 'RPLYTO') { $mailer->AddReplyTo($email_record[email], $email_record[name]); } } } } } $attachments = $adb->pquery('SELECT * FROM vtiger_mailer_queueattachments WHERE id=?', array($queueid)); for ($aidx = 0; $aidx < $adb->num_rows($attachments); ++$aidx) { $attachment_record = $adb->fetch_array($attachments, $aidx); if ($attachment_record['path'] != '') { $mailer->AddAttachment($attachment_record['path'], $attachment_record['name'], $attachment_record['encoding'], $attachment_record['type']); } } $sent = $mailer->Send(true); if ($sent) { Vtiger_Event::trigger('vtiger.mailer.mailsent', $relcrmid); if ($listener) { $listener->mailsent($queueid); } $adb->pquery('DELETE FROM vtiger_mailer_queue WHERE id=?', array($queueid)); $adb->pquery('DELETE FROM vtiger_mailer_queueinfo WHERE id=?', array($queueid)); $adb->pquery('DELETE FROM vtiger_mailer_queueattachments WHERE id=?', array($queueid)); } else { if ($listener) { $listener->mailerror($queueid); } $adb->pquery('UPDATE vtiger_mailer_queue SET failed=?, failreason=? WHERE id=?', array(1, $mailer->ErrorInfo, $queueid)); } } } }
/** * @param $options array **/ function sendNotification($options = array()) { $mmail = new self(); $mmail->AddCustomHeader("Auto-Submitted: auto-generated"); // For exchange $mmail->AddCustomHeader("X-Auto-Response-Suppress: OOF, DR, NDR, RN, NRN"); $mmail->SetFrom($options['from'], $options['fromname']); if ($options['replyto']) { $mmail->AddReplyTo($options['replyto'], $options['replytoname']); } $mmail->Subject = $options['subject']; if (empty($options['content_html'])) { $mmail->isHTML(false); $mmail->Body = $options['content_text']; } else { $mmail->isHTML(true); $mmail->Body = $options['content_html']; $mmail->AltBody = $options['content_text']; } $mmail->AddAddress($options['to'], $options['toname']); if (!empty($options['messageid'])) { $mmail->MessageID = "<" . $options['messageid'] . ">"; } $messageerror = __('Error in sending the email'); if (!$mmail->Send()) { $senderror = true; Session::addMessageAfterRedirect($messageerror . "<br>" . $mmail->ErrorInfo, true); } else { //TRANS to be written in logs %1$s is the to email / %2$s is the subject of the mail Toolbox::logInFile("mail", sprintf(__('%1$s: %2$s'), sprintf(__('An email was sent to %s'), $options['to']), $options['subject'] . "\n")); } $mmail->ClearAddresses(); return true; }