Example #1
0
function WAUE_SendMail($mailObj, $mailAttachments, $mailBCC, $mailCC, $mailTo, $mailImportance, $mailFrom, $mailSubject, $mailBody, $mailRef = "WAUE")
{
    $fromArray = WA_getEmailArray($mailFrom);
    $mailTo2 = "";
    $mailContent = "";
    $mailHeader = "";
    $mailFrom = $fromArray[0][1];
    if ($mailObj->ReturnPath == "") {
        $mailObj->ReturnPath = $fromArray[0][1];
    }
    if ($mailObj->ReplyTo == "") {
        $mailObj->ReplyTo = $fromArray[0][1];
    }
    $isIIS = isset($_SERVER['SERVER_SOFTWARE']) && stristr($_SERVER['SERVER_SOFTWARE'], 'microsoft');
    if ($isIIS) {
        $lineEnd = "\r\n";
    } else {
        $lineEnd = "\n";
    }
    if ($fromArray[0][0] != "") {
        $mailFrom = $fromArray[0][0] . " <" . $fromArray[0][1] . ">";
        if ($isIIS) {
            $mailFrom = $fromArray[0][1];
        }
    }
    $mailHeader .= "MIME-Version: 1.0" . $lineEnd;
    if (sizeof($mailObj->attachments) > 0 && is_array($mailObj->attachments[0])) {
        $mailHeader .= "Content-Type: multipart/mixed";
        if ($mailObj->CharSet != "") {
            $mailHeader .= preg_replace("/[\r\n]/", "", "; charset=\"" . $mailObj->CharSet . "\"");
        }
        $mailHeader .= "; boundary=\"WAMULTIBREAKWA\"" . $lineEnd;
    } else {
        if ($mailObj->BodyFormat == 2 || $mailObj->BodyFormat == 0) {
            $mailHeader .= "Content-Type: multipart/alternative";
            if ($mailObj->CharSet != "") {
                $mailHeader .= preg_replace("/[\r\n]/", "", "; charset=\"" . $mailObj->CharSet . "\"");
            }
            $mailHeader .= "; boundary=\"WAMULTIBREAKWA\"" . $lineEnd;
            $headers = "";
        } else {
            if ($mailObj->BodyFormat == 1) {
                $mailHeader .= "Content-Type: text/plain";
            }
            if ($mailObj->CharSet != "") {
                $mailHeader .= preg_replace("/[\r\n]/", "", "; charset=\"" . $mailObj->CharSet . "\"") . $lineEnd;
            } else {
                $mailHeader .= $lineEnd;
            }
        }
    }
    foreach ($mailObj->recipients as $emailArr) {
        if ($mailTo != "") {
            $mailTo .= ", ";
        }
        if ($mailTo2 != "") {
            $mailTo2 .= ", ";
        }
        if ($emailArr[0] != "") {
            $mailTo .= $emailArr[0];
        }
        if ($emailArr[1] != "" && !$isIIS) {
            $mailTo2 .= $emailArr[1] . " <" . $emailArr[0] . ">";
        } else {
            $mailTo2 .= $emailArr[0];
        }
    }
    if (strpos($mailTo2, "@")) {
        $mailTo = $mailTo2;
    }
    $mailHeader .= preg_replace("/[\r\n]/", "", "From: " . $mailFrom) . $lineEnd;
    foreach ($mailObj->ccrecip as $emailArr) {
        if ($mailCC != "") {
            $mailCC .= ", ";
        }
        if ($emailArr[1] != "" && !$isIIS) {
            $mailCC .= $emailArr[1] . " <" . $emailArr[0] . ">";
        } else {
            $mailCC .= $emailArr[0];
        }
    }
    if (strpos($mailCC, "@")) {
        $mailHeader .= preg_replace("/[\r\n]/", "", "Cc: " . $mailCC) . $lineEnd;
    }
    foreach ($mailObj->bccrecip as $emailArr) {
        if ($mailBCC != "") {
            $mailBCC .= ", ";
        }
        if ($emailArr[1] != "" && !$isIIS) {
            $mailBCC .= $emailArr[1] . " <" . $emailArr[0] . ">";
        } else {
            $mailBCC .= $emailArr[0];
        }
    }
    if (strpos($mailBCC, "@")) {
        $mailHeader .= preg_replace("/[\r\n]/", "", "Bcc: " . $mailBCC) . $lineEnd;
    }
    $mailHeader .= preg_replace("/[\r\n]/", "", "Reply-To: " . $mailObj->ReplyTo) . $lineEnd;
    $mailHeader .= preg_replace("/[\r\n]/", "", "Return-Path: " . $mailObj->ReturnPath . "") . $lineEnd;
    $mailHeader .= preg_replace("/[\r\n]/", "", "X-Sender: " . $mailFrom) . $lineEnd;
    $mailHeader .= preg_replace("/[\r\n]/", "", "X-Priority: " . $mailObj->Importance) . $lineEnd;
    $mailHeader .= "Date: " . date('r (T)') . $lineEnd;
    $theMSGID = $fromArray[0][1];
    $theMSGID = explode("@", $theMSGID);
    if (sizeof($theMSGID) == 1) {
        $theMSGID[] = $theMSGID[0];
    }
    $theMSGID = "<" . rand() . "." . md5($theMSGID[0]) . "@" . $theMSGID[1] . ">";
    $mailHeader .= preg_replace("/[\r\n]/", "", "Message-ID: " . $theMSGID) . $lineEnd;
    if ($mailObj->Organization != "") {
        $mailHeader .= preg_replace("/[\r\n]/", "", "Organization: " . $mailObj->Organization) . $lineEnd;
    }
    if ($mailObj->XMailer != "") {
        $mailHeader .= preg_replace("/[\r\n]/", "", "X-Mailer: " . $mailObj->XMailer) . $lineEnd;
    }
    if ($mailObj->BodyFormat == 2 || $mailObj->BodyFormat == 0 || sizeof($mailObj->attachments) > 0) {
        $mailContent = $lineEnd . "--WAMULTIBREAKWA" . $lineEnd;
        switch ($mailObj->BodyFormat) {
            case 0:
            case 2:
                $splitBreak = "--WAMULTIBREAKWA";
                if (sizeof($mailObj->attachments) > 0) {
                    $mailContent .= "Content-Type: multipart/alternative";
                    if ($mailObj->CharSet != "") {
                        $mailHeader .= preg_replace("/[\r\n]/", "", "; charset=\"" . $mailObj->CharSet . "\"");
                    }
                    $mailContent .= '; boundary="WAATTBREAKWA"' . $lineEnd . $lineEnd . "--WAATTBREAKWA" . $lineEnd;
                    $splitBreak = "--WAATTBREAKWA";
                }
                $mailContent .= "Content-Type: text/plain";
                if ($mailObj->CharSet != "") {
                    $mailContent .= preg_replace("/[\r\n]/", "", "; charset=\"" . $mailObj->CharSet . "\"") . $lineEnd;
                } else {
                    $mailContent .= $lineEnd;
                }
                $mailContent .= "Content-Transfer-Encoding: 8bit" . $lineEnd;
                $theReplace = $lineEnd . $splitBreak . $lineEnd;
                $theReplace .= "Content-Type: text/html";
                if ($mailObj->CharSet != "") {
                    $theReplace .= "; charset=\"" . $mailObj->CharSet . "\"";
                }
                $theReplace .= $lineEnd . $lineEnd;
                if (strpos($mailBody, "<multipartbreak>") === false) {
                    $mailBody = WA_StripTags($mailBody) . "<multipartbreak>" . $mailBody;
                }
                $mailBody = str_replace("<multipartbreak>", $theReplace, $mailBody);
                $mailContent .= $lineEnd . $mailBody;
                $mailContent .= $lineEnd . $splitBreak . "--" . $lineEnd;
                break;
            case 1:
                $mailContent .= "Content-Type: text/plain";
                if ($mailObj->CharSet != "") {
                    $mailContent .= preg_replace("/[\r\n]/", "", "; charset=\"" . $mailObj->CharSet . "\"") . $lineEnd;
                } else {
                    $mailContent .= $lineEnd;
                }
                $mailContent .= "Content-Transfer-Encoding: 8bit" . $lineEnd;
                $mailContent .= $lineEnd . $mailBody;
                break;
        }
    } else {
        $mailContent .= $mailBody;
    }
    if (sizeof($mailObj->attachments) > 0) {
        foreach ($mailObj->attachments as $fileArr) {
            if (is_readable($fileArr[3])) {
                if (strtolower($fileArr[1]) == "base64") {
                    $data = chunk_split(base64_encode(implode("", file($fileArr[3]))));
                } else {
                    $data = implode("", file($fileArr[3]));
                }
                $mailAttachments .= $lineEnd . "--WAMULTIBREAKWA";
                $mailAttachments .= $lineEnd . "Content-Type: " . $fileArr[0];
                if ($fileArr[2] != "") {
                    $mailAttachments .= "; name=\"" . basename($fileArr[2]) . "\"" . $lineEnd;
                } else {
                    $mailAttachments .= "; name=\"" . basename($fileArr[3]) . "\"" . $lineEnd;
                }
                $mailAttachments .= "Content-Transfer-Encoding: " . $fileArr[1] . $lineEnd;
                $mailAttachments .= "Content-Disposition: inline;";
                if ($fileArr[2] != "") {
                    $mailAttachments .= " filename=\"" . basename($fileArr[2]) . "\"" . $lineEnd . $lineEnd;
                } else {
                    $mailAttachments .= " filename=\"" . basename($fileArr[3]) . "\"" . $lineEnd . $lineEnd;
                }
                $mailAttachments .= $data;
            }
        }
    }
    $mailContent = str_replace("<multipartbreak>", "--WAMULTIBREAKWA" . $lineEnd, $mailContent);
    $mailHeader = str_replace("<multipartbreak>", "--WAMULTIBREAKWA" . $lineEnd, $mailHeader);
    $mailContent = $mailContent . $mailAttachments;
    if (!isset($GLOBALS[$mailRef . "_Index"])) {
        $GLOBALS[$mailRef . "_Index"] = 1;
    }
    if (!isset($GLOBALS[$mailRef . "_Log"]) || $GLOBALS[$mailRef . "_Index"] == 1) {
        $GLOBALS[$mailRef . "_Log"] = "";
    }
    $GLOBALS[$mailRef . "_From"] = $mailFrom;
    $GLOBALS[$mailRef . "_To"] = $mailTo;
    $GLOBALS[$mailRef . "_Subject"] = $mailSubject;
    $GLOBALS[$mailRef . "_Body"] = $mailContent;
    $GLOBALS[$mailRef . "_Header"] = $mailHeader;
    $GLOBALS[$mailRef . "_Log"] .= "Sending To: " . $mailTo . "... ";
    set_error_handler(create_function('$errno, $errstr', '$GLOBALS["' . $mailRef . '_Error"] = ($errstr); return true;'));
    if ($mailObj->useAddParams) {
        $mailObj = @mail($mailTo, $mailSubject, $mailContent, $mailHeader, "-f" . $mailFrom . " -r" . $mailObj->ReturnPath);
    } else {
        $mailObj = @mail($mailTo, $mailSubject, $mailContent, $mailHeader);
    }
    restore_error_handler();
    if ($mailObj) {
        $GLOBALS[$mailRef . "_Status"] = "Success";
        $GLOBALS[$mailRef . "_Log"] .= "Success <br>\n";
    } else {
        $GLOBALS[$mailRef . "_Status"] = "Failure";
        $GLOBALS[$mailRef . "_Log"] .= $GLOBALS[$mailRef . "_Error"] . " - Failure <br>\n";
    }
    return $mailObj;
}
Example #2
0
 function processEvent($isError)
 {
     if ($this->ToDo == "none") {
         return true;
     }
     if (sizeof($this->ColumnList) == 0) {
         return false;
     }
     $LogIncludeDirectory = getcwd();
     chdir(dirname(__FILE__));
     require "../../Connections/" . $this->Connection . ".php";
     if (!function_exists("WA_AB_generateInsertParams")) {
         require_once "../database_management/wa_appbuilder_php.php";
     }
     chdir($LogIncludeDirectory);
     eval("\$" . "logConnection = \$" . $this->Connection . ";");
     eval("\$" . "logDatabase = \$" . "database_" . $this->Connection . ";");
     mysql_select_db($logDatabase, $logConnection);
     $insertParams = WA_AB_generateInsertParams($this->ColumnList, $this->TypeList, $this->ValueList, -1);
     switch ($this->ToDo) {
         case "update":
             $emailToValue = "";
             $emailToType = "',none,''";
             for ($n = 0; $n < sizeof($this->ColumnList); $n++) {
                 if ($this->ColumnList[$n] == $this->EmailColumn) {
                     $emailToValue = $this->ValueList[$n];
                     $emailToType = $this->TypeList[$n];
                     break;
                 }
             }
             if (!$emailToValue && isset($_SESSION[$this->MailRef . "_To"])) {
                 $emailToValue = $_SESSION[$this->MailRef . "_To"];
             }
             if ($emailToValue) {
                 $toArrUpdate = WA_getEmailArray($emailToValue);
                 $emailToValue = $toArrUpdate[0][1];
                 if ($emailToValue) {
                     //check to see if record exists then update / insert as needed
                     $whereClause = WA_AB_generateWhereClause(array($this->EmailColumn), array($emailToType), array($emailToValue), array("="));
                     //$logUpdateTest = mysql_query("SELECT ".WA_AB_cleanUpColumnName($this->EmailColumn)." FROM ".WA_AB_cleanUpColumnName($this->TableName)." WHERE ".$whereClause->sqlWhereClause, $logConnection) or die(mysql_error());
                     //if (mysql_num_rows($logUpdateTest) > 0) {
                     //do update
                     $logUpdate = mysql_query("UPDATE " . WA_AB_cleanUpColumnName($this->TableName) . " SET " . $insertParams->WA_setValues . " WHERE " . $whereClause->sqlWhereClause, $logConnection) or die(mysql_error());
                     //break;
                     //}
                 }
             }
             //mysql_free_result($logUpdateTest);
             break;
         case "create":
             //create email_log table in database (if it doesn't exist) and insert
             //creation handled by UI
             //break; // do not break, continue to insert
         //create email_log table in database (if it doesn't exist) and insert
         //creation handled by UI
         //break; // do not break, continue to insert
         case "insert":
             //insert record to table
             $logInsert = mysql_query("INSERT INTO " . WA_AB_cleanUpColumnName($this->TableName) . " (" . $insertParams->WA_tableValues . ") VALUES (" . $insertParams->WA_dbValues . ")", $logConnection) or die(mysql_error());
             break;
     }
     return true;
 }