Viewing File core/phpmailer/class.phpmailer.php of 0.00.1a
|
' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "
\n"; 2122: } 2123: } 2124: $this->ErrorInfo = $msg; 2125: } 2126: 2127: /** 2128: * Returns the proper RFC 822 formatted date. 2129: * @access public 2130: * @return string 2131: * @static 2132: */ 2133: public static function RFCDate() { 2134: $tz = date('Z'); 2135: $tzs = ($tz < 0) ? '-' : '+'; 2136: $tz = abs($tz); 2137: $tz = (int)($tz/3600)*100 + ($tz%3600)/60; 2138: $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); 2139: 2140: return $result; 2141: } 2142: 2143: /** 2144: * Returns the server hostname or 'localhost.localdomain' if unknown. 2145: * @access protected 2146: * @return string 2147: */ 2148: protected function ServerHostname() { 2149: if (!empty($this->Hostname)) { 2150: $result = $this->Hostname; 2151: } elseif (isset($_SERVER['SERVER_NAME'])) { 2152: $result = $_SERVER['SERVER_NAME']; 2153: } else { 2154: $result = 'localhost.localdomain'; 2155: } 2156: 2157: return $result; 2158: } 2159: 2160: /** 2161: * Returns a message in the appropriate language. 2162: * @access protected 2163: * @return string 2164: */ 2165: protected function Lang($key) { 2166: if(count($this->language) < 1) { 2167: $this->SetLanguage('en'); // set the default language 2168: } 2169: 2170: if(isset($this->language[$key])) { 2171: return $this->language[$key]; 2172: } else { 2173: return 'Language string failed to load: ' . $key; 2174: } 2175: } 2176: 2177: /** 2178: * Returns true if an error occurred. 2179: * @access public 2180: * @return bool 2181: */ 2182: public function IsError() { 2183: return ($this->error_count > 0); 2184: } 2185: 2186: /** 2187: * Changes every end of line from CR or LF to CRLF. 2188: * @access public 2189: * @return string 2190: */ 2191: public function FixEOL($str) { 2192: $str = str_replace("\r\n", "\n", $str); 2193: $str = str_replace("\r", "\n", $str); 2194: $str = str_replace("\n", $this->LE, $str); 2195: return $str; 2196: } 2197: 2198: /** 2199: * Adds a custom header. 2200: * @access public 2201: * @return void 2202: */ 2203: public function AddCustomHeader($custom_header) { 2204: $this->CustomHeader[] = explode(':', $custom_header, 2); 2205: } 2206: 2207: /** 2208: * Evaluates the message and returns modifications for inline images and backgrounds 2209: * @access public 2210: * @return $message 2211: */ 2212: public function MsgHTML($message, $basedir = '') { 2213: preg_match_all("/(src|background)=[\"'](.*)[\"']/Ui", $message, $images); 2214: if(isset($images[2])) { 2215: foreach($images[2] as $i => $url) { 2216: // do not change urls for absolute images (thanks to corvuscorax) 2217: if (!preg_match('#^[A-z]+://#', $url)) { 2218: $filename = basename($url); 2219: $directory = dirname($url); 2220: ($directory == '.') ? $directory='': ''; 2221: $cid = 'cid:' . md5($filename); 2222: $ext = pathinfo($filename, PATHINFO_EXTENSION); 2223: $mimeType = self::_mime_types($ext); 2224: if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; } 2225: if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; } 2226: if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) { 2227: $message = preg_replace("/".$images[1][$i]."=[\"']".preg_quote($url, '/')."[\"']/Ui", $images[1][$i]."=\"".$cid."\"", $message); 2228: } 2229: } 2230: } 2231: } 2232: $this->IsHTML(true); 2233: $this->Body = $message; 2234: if (empty($this->AltBody)) { 2235: $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); 2236: if (!empty($textMsg)) { 2237: $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet); 2238: } 2239: } 2240: if (empty($this->AltBody)) { 2241: $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; 2242: } 2243: return $message; 2244: } 2245: 2246: /** 2247: * Gets the MIME type of the embedded or inline image 2248: * @param string File extension 2249: * @access public 2250: * @return string MIME type of ext 2251: * @static 2252: */ 2253: public static function _mime_types($ext = '') { 2254: $mimes = array( 2255: 'hqx' => 'application/mac-binhex40', 2256: 'cpt' => 'application/mac-compactpro', 2257: 'doc' => 'application/msword', 2258: 'bin' => 'application/macbinary', 2259: 'dms' => 'application/octet-stream', 2260: 'lha' => 'application/octet-stream', 2261: 'lzh' => 'application/octet-stream', 2262: 'exe' => 'application/octet-stream', 2263: 'class' => 'application/octet-stream', 2264: 'psd' => 'application/octet-stream', 2265: 'so' => 'application/octet-stream', 2266: 'sea' => 'application/octet-stream', 2267: 'dll' => 'application/octet-stream', 2268: 'oda' => 'application/oda', 2269: 'pdf' => 'application/pdf', 2270: 'ai' => 'application/postscript', 2271: 'eps' => 'application/postscript', 2272: 'ps' => 'application/postscript', 2273: 'smi' => 'application/smil', 2274: 'smil' => 'application/smil', 2275: 'mif' => 'application/vnd.mif', 2276: 'xls' => 'application/vnd.ms-excel', 2277: 'ppt' => 'application/vnd.ms-powerpoint', 2278: 'wbxml' => 'application/vnd.wap.wbxml', 2279: 'wmlc' => 'application/vnd.wap.wmlc', 2280: 'dcr' => 'application/x-director', 2281: 'dir' => 'application/x-director', 2282: 'dxr' => 'application/x-director', 2283: 'dvi' => 'application/x-dvi', 2284: 'gtar' => 'application/x-gtar', 2285: 'php' => 'application/x-httpd-php', 2286: 'php4' => 'application/x-httpd-php', 2287: 'php3' => 'application/x-httpd-php', 2288: 'phtml' => 'application/x-httpd-php', 2289: 'phps' => 'application/x-httpd-php-source', 2290: 'js' => 'application/x-javascript', 2291: 'swf' => 'application/x-shockwave-flash', 2292: 'sit' => 'application/x-stuffit', 2293: 'tar' => 'application/x-tar', 2294: 'tgz' => 'application/x-tar', 2295: 'xhtml' => 'application/xhtml+xml', 2296: 'xht' => 'application/xhtml+xml', 2297: 'zip' => 'application/zip', 2298: 'mid' => 'audio/midi', 2299: 'midi' => 'audio/midi', 2300: 'mpga' => 'audio/mpeg', 2301: 'mp2' => 'audio/mpeg', 2302: 'mp3' => 'audio/mpeg', 2303: 'aif' => 'audio/x-aiff', 2304: 'aiff' => 'audio/x-aiff', 2305: 'aifc' => 'audio/x-aiff', 2306: 'ram' => 'audio/x-pn-realaudio', 2307: 'rm' => 'audio/x-pn-realaudio', 2308: 'rpm' => 'audio/x-pn-realaudio-plugin', 2309: 'ra' => 'audio/x-realaudio', 2310: 'rv' => 'video/vnd.rn-realvideo', 2311: 'wav' => 'audio/x-wav', 2312: 'bmp' => 'image/bmp', 2313: 'gif' => 'image/gif', 2314: 'jpeg' => 'image/jpeg', 2315: 'jpg' => 'image/jpeg', 2316: 'jpe' => 'image/jpeg', 2317: 'png' => 'image/png', 2318: 'tiff' => 'image/tiff', 2319: 'tif' => 'image/tiff', 2320: 'css' => 'text/css', 2321: 'html' => 'text/html', 2322: 'htm' => 'text/html', 2323: 'shtml' => 'text/html', 2324: 'txt' => 'text/plain', 2325: 'text' => 'text/plain', 2326: 'log' => 'text/plain', 2327: 'rtx' => 'text/richtext', 2328: 'rtf' => 'text/rtf', 2329: 'xml' => 'text/xml', 2330: 'xsl' => 'text/xml', 2331: 'mpeg' => 'video/mpeg', 2332: 'mpg' => 'video/mpeg', 2333: 'mpe' => 'video/mpeg', 2334: 'qt' => 'video/quicktime', 2335: 'mov' => 'video/quicktime', 2336: 'avi' => 'video/x-msvideo', 2337: 'movie' => 'video/x-sgi-movie', 2338: 'doc' => 'application/msword', 2339: 'word' => 'application/msword', 2340: 'xl' => 'application/excel', 2341: 'eml' => 'message/rfc822' 2342: ); 2343: return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; 2344: } 2345: 2346: /** 2347: * Set (or reset) Class Objects (variables) 2348: * 2349: * Usage Example: 2350: * $page->set('X-Priority', '3'); 2351: * 2352: * @access public 2353: * @param string $name Parameter Name 2354: * @param mixed $value Parameter Value 2355: * NOTE: will not work with arrays, there are no arrays to set/reset 2356: * @todo Should this not be using __set() magic function? 2357: */ 2358: public function set($name, $value = '') { 2359: try { 2360: if (isset($this->$name) ) { 2361: $this->$name = $value; 2362: } else { 2363: throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL); 2364: } 2365: } catch (Exception $e) { 2366: $this->SetError($e->getMessage()); 2367: if ($e->getCode() == self::STOP_CRITICAL) { 2368: return false; 2369: } 2370: } 2371: return true; 2372: } 2373: 2374: /** 2375: * Strips newlines to prevent header injection. 2376: * @access public 2377: * @param string $str String 2378: * @return string 2379: */ 2380: public function SecureHeader($str) { 2381: $str = str_replace("\r", '', $str); 2382: $str = str_replace("\n", '', $str); 2383: return trim($str); 2384: } 2385: 2386: /** 2387: * Set the private key file and password to sign the message. 2388: * 2389: * @access public 2390: * @param string $key_filename Parameter File Name 2391: * @param string $key_pass Password for private key 2392: */ 2393: public function Sign($cert_filename, $key_filename, $key_pass) { 2394: $this->sign_cert_file = $cert_filename; 2395: $this->sign_key_file = $key_filename; 2396: $this->sign_key_pass = $key_pass; 2397: } 2398: 2399: /** 2400: * Set the private key file and password to sign the message. 2401: * 2402: * @access public 2403: * @param string $key_filename Parameter File Name 2404: * @param string $key_pass Password for private key 2405: */ 2406: public function DKIM_QP($txt) { 2407: $tmp = ''; 2408: $line = ''; 2409: for ($i = 0; $i < strlen($txt); $i++) { 2410: $ord = ord($txt[$i]); 2411: if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) { 2412: $line .= $txt[$i]; 2413: } else { 2414: $line .= "=".sprintf("%02X", $ord); 2415: } 2416: } 2417: return $line; 2418: } 2419: 2420: /** 2421: * Generate DKIM signature 2422: * 2423: * @access public 2424: * @param string $s Header 2425: */ 2426: public function DKIM_Sign($s) { 2427: $privKeyStr = file_get_contents($this->DKIM_private); 2428: if ($this->DKIM_passphrase != '') { 2429: $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase); 2430: } else { 2431: $privKey = $privKeyStr; 2432: } 2433: if (openssl_sign($s, $signature, $privKey)) { 2434: return base64_encode($signature); 2435: } 2436: } 2437: 2438: /** 2439: * Generate DKIM Canonicalization Header 2440: * 2441: * @access public 2442: * @param string $s Header 2443: */ 2444: public function DKIM_HeaderC($s) { 2445: $s = preg_replace("/\r\n\s+/", " ", $s); 2446: $lines = explode("\r\n", $s); 2447: foreach ($lines as $key => $line) { 2448: list($heading, $value) = explode(":", $line, 2); 2449: $heading = strtolower($heading); 2450: $value = preg_replace("/\s+/", " ", $value) ; // Compress useless spaces 2451: $lines[$key] = $heading.":".trim($value) ; // Don't forget to remove WSP around the value 2452: } 2453: $s = implode("\r\n", $lines); 2454: return $s; 2455: } 2456: 2457: /** 2458: * Generate DKIM Canonicalization Body 2459: * 2460: * @access public 2461: * @param string $body Message Body 2462: */ 2463: public function DKIM_BodyC($body) { 2464: if ($body == '') return "\r\n"; 2465: // stabilize line endings 2466: $body = str_replace("\r\n", "\n", $body); 2467: $body = str_replace("\n", "\r\n", $body); 2468: // END stabilize line endings 2469: while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") { 2470: $body = substr($body, 0, strlen($body) - 2); 2471: } 2472: return $body; 2473: } 2474: 2475: /** 2476: * Create the DKIM header, body, as new header 2477: * 2478: * @access public 2479: * @param string $headers_line Header lines 2480: * @param string $subject Subject 2481: * @param string $body Body 2482: */ 2483: public function DKIM_Add($headers_line, $subject, $body) { 2484: $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms 2485: $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body 2486: $DKIMquery = 'dns/txt'; // Query method 2487: $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) 2488: $subject_header = "Subject: $subject"; 2489: $headers = explode($this->LE, $headers_line); 2490: foreach($headers as $header) { 2491: if (strpos($header, 'From:') === 0) { 2492: $from_header = $header; 2493: } elseif (strpos($header, 'To:') === 0) { 2494: $to_header = $header; 2495: } 2496: } 2497: $from = str_replace('|', '=7C', $this->DKIM_QP($from_header)); 2498: $to = str_replace('|', '=7C', $this->DKIM_QP($to_header)); 2499: $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable 2500: $body = $this->DKIM_BodyC($body); 2501: $DKIMlen = strlen($body) ; // Length of body 2502: $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body 2503: $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";"; 2504: $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n". 2505: "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n". 2506: "\th=From:To:Subject;\r\n". 2507: "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n". 2508: "\tz=$from\r\n". 2509: "\t|$to\r\n". 2510: "\t|$subject;\r\n". 2511: "\tbh=" . $DKIMb64 . ";\r\n". 2512: "\tb="; 2513: $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); 2514: $signed = $this->DKIM_Sign($toSign); 2515: return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; 2516: } 2517: 2518: protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) { 2519: if (!empty($this->action_function) && function_exists($this->action_function)) { 2520: $params = array($isSent, $to, $cc, $bcc, $subject, $body); 2521: call_user_func_array($this->action_function, $params); 2522: } 2523: } 2524: } 2525: 2526: class phpmailerException extends Exception { 2527: public function errorMessage() { 2528: $errorMsg = '' . $this->getMessage() . "