function errSend() { /* check for valid email settings */ $settings = new dbSelect("esettings", "cubit"); $settings->run(); if ($settings->num_rows() <= 0) { r2sListSet("emailsettings"); header("Location: email-settings.php"); exit; } $settings->fetch_array(); $server = $settings->d["smtp_host"]; $from = $settings->d["fromname"]; $reply = $settings->d["reply"]; /* build the email */ $data = errData($_GET["id"]); $msg = new clsMailMsg(); $msg->newMessage($from, $reply, "Error Report: {$data['errtime']}", "Error report file attached."); $msg->addAttachment("application/octet-stream", "error{$_GET['id']}-{$data['errtime']}.cer", $data["errdata"]); $md = $msg->getNewMessage(); /* send the email */ /** * ok, so lets stop catching errors because if the email sending fails * we are just going to go back to "an error has occured" */ disableErrorNet(); $smtp = new clsSMTPMail(); $smtp->sendMessages($server, 25, false, false, false, ERRORNET_EMAIL, $md["from"], $md["subject"], $md["body"], $md["headers"]); $OUTPUT = "<h3>Error Report</h3>"; if ($smtp->bool_success !== true) { $OUTPUT .= "Error sending report. Please save report and email it\n\t\t\tto <a class='nav' href='mailto: " . ERRORNET_EMAIL . "'>" . ERRORNET_EMAIL . "</a><br />\n\t\t\t<br />\n\t\t\t<input type='button' value='Save Error Report'\n\t\t\t\tonClick='document.location.href=\"" . relpath("geterror.php") . "?id={$_GET['id']}\";' />"; } else { $OUTPUT .= "Successfully sent report. Thank You."; } return $OUTPUT; }
/** * sends a trh message. * * if you dont pass the trh config variable, it will be fetched automatically. * * @param string $who must be "supp" or "cust", what other side is too me * @param int $id customer/supplier id * @param string $msgtype 6 character message type * @param string $data what to send * @param array $config optionally the companies trh configuration * @return bool */ function send_trhmsg($who, $id, $email, $msgtype, $data, $config = false) { if (defined("CONSOLE")) { print "sending response:\n"; print "\twho: {$who}\n"; print "\tid: {$id}\n"; print "\tmsgtype: {$msgtype}\n"; print "\tdata: {$data}\n"; } require_lib("mail.smtp"); require_lib("mail.msg"); /* configuration */ if ($config === false) { $config = getTrhConfig(); } extract($config); /* determines new message parameters */ $subject = "trh_{$msgtype}"; $body = array(); $attachments = array(); $headers = array(); $compinfo = qryCompInfo(); /* determine my ip address */ if (empty($_SERVER["SERVER_NAME"])) { $myipaddr = "0.0.0.0"; } else { $myipaddr = gethostbyname($_SERVER['SERVER_NAME']); } /* determine key request function */ if ($who == "supp") { $keyFunc = "trhKeySupp"; } else { $keyFunc = "trhKeyCust"; } /* standard message body details */ $body[] = "compname: {$compinfo['compname']}"; $body[] = "ipaddr: {$myipaddr}"; $body[] = "bustel: {$compinfo['tel']}"; $body[] = "fromwho: " . ($who == "supp" ? "cust" : "supp"); $body[] = "email: {$SMTP_FROM}"; switch ($msgtype) { /* request a new key */ case "reqkey": $subject .= " {$data}"; break; /* respond to a newly requested key */ /* respond to a newly requested key */ case "rspkey": /* get my key from this guy */ $qry = new dbSelect("keys", "trh", grp(m("cols", "(key).send_key AS mykey"), m("where", "{$who}id='{$id}'"))); $qry->run(); if ($qry->num_rows() <= 0) { return false; } $d = $qry->fetch_array(); $mykey = $d["mykey"]; $subject .= " {$data}"; $body[] = "mykey: {$mykey}"; break; /* requests a new purchase */ /* requests a new purchase */ case "reqpur": $keys = $keyFunc($id, "recv_key, send_key"); $subject .= " {$keys['send_key']}"; $body[] = "yourkey: {$keys['recv_key']}"; $attachments["data.xml"] = $data; break; /* responds to a new purchase request */ /* responds to a new purchase request */ case "rsppur": $keys = $keyFunc($id, "recv_key, send_key"); $subject .= " {$keys['send_key']}"; $body[] = "yourkey: {$keys['recv_key']}"; $body[] = "purid: {$data['purid']}"; $body[] = "status: {$data['status']}"; break; } /* create new mail message */ $msg = new clsMailMsg(); $msg->newMessage($SMTP_FROM, $SMTP_FROM, $subject, implode("\n", $body), $headers, true); if (count($attachments)) { foreach ($attachments as $fname => $contents) { $msg->addAttachment("text/plain", $fname, $data); } } $smtp = new clsSMTPMail(); $ret = $smtp->sendMessages($SMTP_SERVER, 25, !empty($SMTP_USER), $SMTP_USER, $SMTP_PASS, $email, $msg->getNewMessage()); if ($smtp->bool_success !== true) { return $ret; } return true; }