function sendDBEmail() { // This function picks up an unsent mail from the Database and sends it. // This is desgined to be run from CRON // Returns: // 1 on No mail, // 2 on Sent a Mail Successfully // 3 on failed sending mail, i.e. there was an error global $db; $owner = siteDets(); require_once '/srv/athenace/lib/pub/PHPMailer-5.2.10/PHPMailerAutoload.php'; $sqltext = "SELECT * FROM mail WHERE sent=? AND body<>'' LIMIT 1;"; // rint $sqltext. "\n"; $q = $db->select($sqltext, array(0), 'i'); if (!empty($q)) { $r = $q[0]; $mailid = $r->mailid; $name = stripslashes($r->addname); $email = stripslashes($r->addto); $esubject = stripslashes($r->subject); $htmlBody = stripcslashes($r->body); $docName = $r->docname; $docTitle = $r->doctitle; $owner = siteDets(); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only $mail->SMTPAuth = true; // turn on SMTP authentication $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to $mail->Host = $owner->emailsmtpsrv; $mail->Username = $owner->athenaemail; // SMTP username $mail->Password = $owner->athenaemailpw; // SMTP password $mail->From = $owner->email; $mail->FromName = $owner->co_name; $mail->AddAddress($email, $name); $mail->AddReplyTo($owner->email, $owner->co_name); // Reply to this email ID $mail->WordWrap = 50; // set word wrap $mail->IsHTML(true); // send as HTML $mail->Subject = $esubject; $mail->Body = $htmlBody; // HTML Body $htmlTextBody = 'Please see the HTML version of this mail to read the contents.'; $mail->AltBody = $htmlTextBody; // Text Body // PDF Attachment if (file_exists($docName)) { $mail->AddAttachment($docName, $docTitle); // attachment } $email_done = ''; if (!$mail->Send()) { $email_done = "Mailer Error: " . $mail->ErrorInfo; // Send a message to Developer to let them know something is wrong // passthru('../shared/sysmail.php'); return 3; } else { # Update DB $mailUpdate = new Mail(); $mailUpdate->setMailid($mailid); $mailUpdate->setSent(time()); $mailUpdate->updateDB(); } return 2; } else { // No Mail return 1; } }
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ $pagetitle = "Invoices"; $navtitle = 'Invoices'; $keywords = ''; $description = ''; include "/srv/athenace/lib/shared/common.php"; include "/srv/athenace/lib/intranet/common.php"; include "/srv/athenace/lib/shared/functions_form.php"; $owner = siteDets(); $done = 0; // Check if we have Form Data to process if (isset($_GET['go']) && $_GET['go'] == "y") { if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id']) { $logContent = 'Invoice Paid for InvoiceID:' . $_GET['id']; # Update DB $invoicesUpdate = new Invoices(); $invoicesUpdate->setInvoicesid($_GET['id']); $invoicesUpdate->setPaid(time()); $invoicesUpdate->updateDB(); $logresult = logEvent(26, $logContent); $done = 1; } } if (isset($_GET['go']) && $_GET['go'] == "undopaid") {