Index: trunk/kernel/include/emailmessage.php =================================================================== diff -u -r3508 -r3515 --- trunk/kernel/include/emailmessage.php (.../emailmessage.php) (revision 3508) +++ trunk/kernel/include/emailmessage.php (.../emailmessage.php) (revision 3515) @@ -709,121 +709,120 @@ return true; } - function DeliverMail($To,$From,$Subject,$Msg,$headers, $ForceSend=0) - { - global $MessagesSent,$objConfig; + function DeliverMail($To,$From,$Subject,$Msg,$headers, $ForceSend=0) + { + global $MessagesSent,$objConfig; - if(($this->MessagesSent >$this->MessagesAtOnce) && !$ForceSend) - { - $this->EnqueueMail($To,$From,$Subject,$Msg,$headers); - return TRUE; - } - else - { + if(($this->MessagesSent >$this->MessagesAtOnce) && !$ForceSend) + { + $this->EnqueueMail($To,$From,$Subject,$Msg,$headers); + return TRUE; + } + else + { + $this->MessagesSent++; - $this->MessagesSent++; + $time = adodb_mktime(); + $conn = &GetADODBConnection(); - $time = adodb_mktime(); - $conn = &GetADODBConnection(); + /* $sql = "INSERT INTO ".GetTablePrefix()."EmailLog VALUES ('', '".htmlspecialchars($From)."', '".htmlspecialchars($To)."', '$Subject', $time, '')"; + $conn->Execute($sql);*/ + /* ensure headers are using \n instead of \n */ -/* $sql = "INSERT INTO ".GetTablePrefix()."EmailLog VALUES ('', '".htmlspecialchars($From)."', '".htmlspecialchars($To)."', '$Subject', $time, '')"; - $conn->Execute($sql);*/ - /* ensure headers are using \r\n instead of \n */ + $headers = "Date: ".adodb_date("r")."\n".$headers; + $headers = "Return-Path: ".$objConfig->Get("Smtp_AdminMailFrom")."\n".$headers; - $headers = "Date: ".adodb_date("r")."\n".$headers; - $headers = "Return-Path: ".$objConfig->Get("Smtp_AdminMailFrom")."\n".$headers; + $headers = str_replace("\n\n","\r\n\r\n",$headers); + $headers = str_replace("\r\n","\n",$headers); + //$headers = str_replace("\n","\r\n",$headers); - $headers = str_replace("\n\n","\r\n\r\n",$headers); - $headers = str_replace("\r\n","\n",$headers); - //$headers = str_replace("\n","\r\n",$headers); + // if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) { + $Msg = str_replace("\n\n","\r\n\r\n",$Msg); + $Msg = str_replace("\r\n","\n",$Msg); + //$Msg = str_replace("\n","\r\n",$Msg); + // } - // if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) { - $Msg = str_replace("\n\n","\r\n\r\n",$Msg); - $Msg = str_replace("\r\n","\n",$Msg); - //$Msg = str_replace("\n","\r\n",$Msg); - // } + //echo "
"; print_r(htmlentities($headers)); echo "
"; + //echo "
"; print_r(htmlentities($Msg)); echo "
"; + $ver = phpversion(); + if(substr($Subject,0,9)=="Subject: ") + $Subject = substr($Subject,9); + if(!strlen($objConfig->Get("Smtp_Server")) || !$this->AllowSockets()) + { + return mail($To,trim($Subject),$Msg, $headers); + } - //echo "
"; print_r(htmlentities($headers)); echo "
"; - //echo "
"; print_r(htmlentities($Msg)); echo "
"; - $ver = phpversion(); - if(substr($Subject,0,9)=="Subject: ") - $Subject = substr($Subject,9); - if(!strlen($objConfig->Get("Smtp_Server")) || !$this->AllowSockets()) - { - return mail($To,trim($Subject),$Msg, $headers); - } + $headers = "Subject: ".trim($Subject)."\n".$headers; - $headers = "Subject: ".trim($Subject)."\n".$headers; + $send_params['recipients'] = array($To); // The recipients (can be multiple) + $send_params['from'] = $From; // This is used as in the MAIL FROM: cmd + $send_params['headers'] = explode("\n",$headers); + // It should end up as the Return-Path: header + $send_params['body'] = $Msg; // The body of the email - $send_params['recipients'] = array($To); // The recipients (can be multiple) - $send_params['from'] = $From; // This is used as in the MAIL FROM: cmd - $send_params['headers'] = explode("\n",$headers); - // It should end up as the Return-Path: header - $send_params['body'] = $Msg; // The body of the email + $params['host'] = $objConfig->Get("Smtp_Server"); // The smtp server host/ip - $params['host'] = $objConfig->Get("Smtp_Server"); // The smtp server host/ip + $params['port'] = 25; // The smtp server port + $params['hello'] = 'INPORTAL'; // What to use when sending the helo command. Typically, your domain/hostname + if($objConfig->Get("Smtp_Authenticate")) // Whether to use basic authentication or not + { + $params['auth'] = TRUE; + $params['user'] = $objConfig->Get("Smtp_User"); + $params['pass'] = $objConfig->get("Smtp_Pass"); + } + else + $params['auth'] = FALSE; + $this->LogLevel=0; + $SmtpServer = new smtp($params); + if($this->LogLevel>0) + { + $SmtpServer->debug=1; + foreach($params as $key=>$value) + { + $this->WriteToMailLog($key."=".$value); + } + } + else + { + //$SmtpServer->debug = 1; + } + $connected = $SmtpServer->connect(); - $params['port'] = 25; // The smtp server port - $params['hello'] = 'INPORTAL'; // What to use when sending the helo command. Typically, your domain/hostname - if($objConfig->Get("Smtp_Authenticate")) // Whether to use basic authentication or not - { - $params['auth'] = TRUE; - $params['user'] = $objConfig->Get("Smtp_User"); - $params['pass'] = $objConfig->get("Smtp_Pass"); - } - else - $params['auth'] = FALSE; - $this->LogLevel=0; - $SmtpServer = new smtp($params); - if($this->LogLevel>0) - { - $SmtpServer->debug=1; - foreach($params as $key=>$value) - { - $this->WriteToMailLog($key."=".$value); - } - } - else - { - //$SmtpServer->debug = 1; - } - $connected = $SmtpServer->connect(); + if($connected) + { + if($this->LogLevel>1) + { + $this->WriteToMailLog("Connected to ".$params['host']); + } + $res = $SmtpServer->send($send_params); + } + $SmtpServer->disconnect(); - if($connected) - { - if($this->LogLevel>1) - { - $this->WriteToMailLog("Connected to ".$params['host']); - } - $res = $SmtpServer->send($send_params); - } - $SmtpServer->disconnect(); + if($this->LogLevel>1) + { + foreach($SmtpServer->buffer as $l) + { + $this->WriteToMailLog($l); + } + } - if($this->LogLevel>1) - { - foreach($SmtpServer->buffer as $l) - { - $this->WriteToMailLog($l); - } - } + if($this->LogLevel>0) + { + if(count($SmtpServer->errors)>0) + { + foreach($SmtpServer->errors as $e) + { + $this->WriteToMailLog($e); + } + } + else + $this->WriteToMailLog("Message to $From Delivered Successfully"); + } + unset($SmtpServer); + return $res; + } + } - if($this->LogLevel>0) - { - if(count($SmtpServer->errors)>0) - { - foreach($SmtpServer->errors as $e) - { - $this->WriteToMailLog($e); - } - } - else - $this->WriteToMailLog("Message to $From Delivered Successfully"); - } - unset($SmtpServer); - return $res; - } - } - function EnqueueMail($To,$From,$Subject,$Msg,$headers) { global $objSession; @@ -877,12 +876,21 @@ { $HasFile = FALSE; $HasFile = (strlen($FileName)>0); - $OB="----=_OuterBoundary_000"; + $OB="----=_OuterBoundary_000".md5( uniqid (rand())); $boundary = "-----=".md5( uniqid (rand())); $f = "\"$FromName\" <".$From.">"; - $headers = "From: $f\r\n"; - $headers .= "MIME-Version: 1.0\r\n"; + $headers = "From: $f\n"; + if(strlen($ToName)>0) + { + $To = "\"$ToName\" <$ToAddr>"; + } + else { + $To = "<".$ToAddr.">"; + } + $headers.="To: $To\n"; + $headers .= "MIME-Version: 1.0\n"; + $conn = &GetADODBConnection(); $time = adodb_mktime(); @@ -898,55 +906,55 @@ $sql = "INSERT INTO ".GetTablePrefix()."EmailLog VALUES ('', ".$conn->qstr($FromName).", ".$conn->qstr($sendTo).", ".$conn->qstr( str_replace("Subject:", "", $Subject) ).", $time, '$SendEvent')"; $conn->Execute($sql); + $msg .="This is a multi-part message in MIME format.\n\n"; if($HasFile) { //Messages start with text/html alternatives in OB - $headers.="Content-Type: multipart/mixed;\r\n\tboundary=\"".$OB."\"\r\n\r\n"; + $headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n\n"; $msg.="--".$OB."\n"; - $msg.="Content-Type: multipart/alternative; boundary=\"$boundary\"\r\n\r\n"; + $msg.="Content-Type: multipart/alternative; boundary=\"$boundary\"\n\n\n"; } - else - $headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\""; + else { + $headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"\n"; + } if(is_array($extra_headers)) { for($i=0;$i0) { $msg .= "--" . $boundary . "\n"; $msg .= "Content-Type: text/html; charset=\"iso-8859-1\"\n"; - $msg .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; + $msg .= "Content-Transfer-Encoding: 8bit\n\n"; $msg .= stripslashes($Html); - $msg .= "\r\n\r\n"; + $msg .= "\n\n"; } - $msg .= "--" . $boundary . "--\n\r"; + $msg .= "--" . $boundary . "--\n"; if($HasFile) { if(!strlen($FileLoc)) { $FileLoc = $FileName; } $FileName = basename($FileName); $msg .= "\n--".$OB."\n"; - $msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\r\n"; + $msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n"; $msg.="Content-Transfer-Encoding: base64\n"; - $msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\r\n\r\n"; + $msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n"; //file goes here $fd=fopen ($FileLoc, "r"); @@ -956,19 +964,10 @@ fclose ($fd); } $FileContent=chunk_split(base64_encode($FileContent)); - $msg .= $FileContent; - $msg .= $OB."--\r\n"; + $msg .= $FileContent."\n"; + $msg .= "--".$OB."--\n"; } - if(strlen($ToName)>0) - { - $To = "\"$ToName\" <$ToAddr>"; - } - else { - $To = "<".$ToAddr.">"; - } - - //$headers.="To: $To\r\n"; if($this->MessagesSent>$this->MessagesAtOnce || $QueueOnly==1) { $this->EnqueueMail($ToAddr,$From,$Subject,$msg,$headers);