static function testNotification() { global $CFG_GLPI; $mmail = new GLPIMailer(); $mmail->AddCustomHeader("Auto-Submitted: auto-generated"); // For exchange $mmail->AddCustomHeader("X-Auto-Response-Suppress: OOF, DR, NDR, RN, NRN"); $mmail->SetFrom($CFG_GLPI["admin_email"], $CFG_GLPI["admin_email_name"], false); $mmail->AddAddress($CFG_GLPI["admin_email"], $CFG_GLPI["admin_email_name"]); $mmail->Subject = "[GLPI] " . __('Mail test'); $mmail->Body = __('This is a test email.') . "\n-- \n" . $CFG_GLPI["mailing_signature"]; if (!$mmail->Send()) { Session::addMessageAfterRedirect(__('Failed to send test email to administrator'), false, ERROR); } else { Session::addMessageAfterRedirect(__('Test email sent to administrator')); } }
/** * @param $to (default '') * @param $subject (default '') **/ function sendMailRefusedResponse($to = '', $subject = '') { global $CFG_GLPI; $mmail = new GLPIMailer(); $mmail->AddCustomHeader("Auto-Submitted: auto-replied"); $mmail->SetFrom($CFG_GLPI["admin_email"], $CFG_GLPI["admin_email_name"]); $mmail->AddAddress($to); // Normalized header, no translation $mmail->Subject = 'Re: ' . $subject; $mmail->Body = __("Your email could not be processed.\nIf the problem persists, contact the administrator") . "\n-- \n" . $CFG_GLPI["mailing_signature"]; $mmail->Send(); }
/** * Send mai lin queue * * @param $ID integer ID of the item * * @return true if send false if not **/ function sendMailById($ID) { global $CFG_GLPI; if ($this->getFromDB($ID)) { $mmail = new GLPIMailer(); $headers = importArrayFromDB($this->fields['headers']); if (is_array($headers) && count($headers)) { foreach ($headers as $key => $val) { $mmail->AddCustomHeader("{$key}: {$val}"); } } // Add custom header for mail grouping in reader $mmail->AddCustomHeader("In-Reply-To: GLPI-" . $this->fields["itemtype"] . "-" . $this->fields["items_id"]); $mmail->SetFrom($this->fields['sender'], $this->fields['sendername']); if ($this->fields['replyto']) { $mmail->AddReplyTo($this->fields['replyto'], $this->fields['replytoname']); } $mmail->Subject = $this->fields['name']; if (empty($this->fields['body_html'])) { $mmail->isHTML(false); $mmail->Body = $this->fields['body_text']; } else { $mmail->isHTML(true); $mmail->Body = ''; $this->fields['body_html'] = Html::entity_decode_deep($this->fields['body_html']); $documents = importArrayFromDB($this->fields['documents']); $link_doc = array(); if (is_array($documents) && count($documents)) { $doc = new Document(); foreach ($documents as $docID) { $doc->getFromDB($docID); // Add embeded image if tag present in ticket content if (preg_match_all('/' . Document::getImageTag($doc->fields['tag']) . '/', $this->fields['body_html'], $matches, PREG_PATTERN_ORDER)) { $mmail->AddEmbeddedImage(GLPI_DOC_DIR . "/" . $doc->fields['filepath'], Document::getImageTag($doc->fields['tag']), $doc->fields['filename'], 'base64', $doc->fields['mime']); // Else Add link to the document } else { $link_doc[] = "<a href='" . rtrim($CFG_GLPI["url_base"], '/') . "/front/document.send.php?docid=" . $doc->fields['id'] . "' >" . $doc->fields['name'] . "</a>"; } } } $mmail->Body .= $this->fields['body_html']; if (count($link_doc)) { $mmail->Body .= '<p style="border:1px solid #cccccc;padding:5px">' . '<b>' . _n('Associated item', 'Associated items', Session::getPluralNumber()) . ' : </b>' . implode(', ', $link_doc) . '</p>'; } $mmail->AltBody = $this->fields['body_text']; } $mmail->AddAddress($this->fields['recipient'], $this->fields['recipientname']); if (!empty($this->fields['messageid'])) { $mmail->MessageID = "<" . $this->fields['messageid'] . ">"; } $messageerror = __('Error in sending the email'); if (!$mmail->Send()) { Session::addMessageAfterRedirect($messageerror . "<br>" . $mmail->ErrorInfo, true); $mmail->ClearAddresses(); $this->update(array('id' => $this->fields['id'], 'sent_try' => $this->fields['sent_try'] + 1)); return false; } 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'), $this->fields['recipient']), $this->fields['name'] . "\n")); $mmail->ClearAddresses(); $this->update(array('id' => $this->fields['id'], 'sent_time' => $_SESSION['glpi_currenttime'])); $this->delete(array('id' => $this->fields['id'])); return true; } } else { return false; } }