--- activeMailLib.php.orig	Thu Nov 17 15:14:56 2005
+++ activeMailLib.php	Thu Nov 17 15:15:04 2005
@@ -179,7 +179,7 @@
 		foreach($this->mailto as $res){
 		$serv=$this->mkCheckServer($res);
 		$this->serv[$res]=$serv[1];
-			if ($serv[0]==true) $this->mailsent[$res]=mail($res, $this->mailsubj, $this->mailbody, $this->mailheaders);
+			if ($serv[0]==true) $this->mailsent[$res]=mail($res, $this->encodeHeader($this->mailsubj), $this->mailbody, $this->mailheaders);
 			else $this->mailsent[$res]=false;
 		}
 	}
@@ -314,6 +314,20 @@
 return $result;
 }
 //==============================================================================================
+// PRIVATE encodeHeader() -> encodes mail headers
+//==============================================================================================
+function encodeHeader($hdr_str)
+{
+	preg_match_all('/(\w*[\x80-\xFF]+\w*)/', $hdr_str, $matches);
+	foreach ($matches[1] as $value) {
+		$replacement = preg_replace('/([\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
+		$hdr_str = str_replace($value, '=?' . $this->charset . '?Q?' . $replacement . '?=', $hdr_str);
+	}
+	
+	return $hdr_str;
+}
+
+//==============================================================================================
 // PRIVATE mkHeaders() -> generates the mail headers
 //==============================================================================================
 function mkHeaders(){
@@ -321,7 +335,7 @@
 $this->headers["Content-Type"]="text/$this->type; charset=\"$this->charset\"";
 $this->headers["Content-Transfer-Encoding"]="$this->encoding";
 	if ($this->mailfrom){
-		if ($this->mailfromname) $this->headers["From"] = $this->mailfromname." <".$this->mailfrom.">";
+		if ($this->mailfromname) $this->headers["From"] = $this->encodeHeader($this->mailfromname)." <".$this->mailfrom.">";
 		else $this->headers["From"] = $this->mailfrom;
 	}
 	if ($this->mailcc) $this->headers["Cc"] = $this->mailcc;
