function connect($host, $user, $pass, $port = 110, $ssl = false, $timeout = 30) { $setver = true; if (is_string($host)) { $host = FUNC::str_clear($host); $host = trim($host); if ($host != "") { if (FUNC::is_ipv4($host)) { $iphost = $host; } else { $iphost = gethostbyname($host); if ($iphost == $host) { $setver = false; trigger_error('Invalid 3 hostname value "' . $host . '" (doesn\'t have an IPv4 address), on class POP3::connect()', 512); } } } else { $setver = false; trigger_error('Invalid 2 hostname/ip value, on class POP3::connect()', 512); } } else { $setver = false; trigger_error('Invalid 1 hostname/ip type value, on class POP3::connect()', 512); } if (is_string($user)) { $user = FUNC::str_clear($user); $user = trim($user); if ($user == "") { $setver = false; trigger_error('Invalid 2 username value, on class POP3::connect()', 512); } } else { $setver = false; trigger_error('Invalid 1 username type value, on class POP3::connect()', 512); } if (is_string($pass)) { $pass = FUNC::str_clear($pass); $pass = trim($pass); if ($pass == "") { $setver = false; trigger_error('Invalid 2 password value, on class POP3::connect()', 512); } } else { $setver = false; trigger_error('Invalid 1 password type value, on class POP3::connect()', 512); } if (!is_int($port)) { $port = 110; trigger_error('Invalid port type value, on class POP3::connect()', 512); } if (is_string($ssl)) { $ssl = FUNC::str_clear($ssl); $ssl = trim(strtolower($ssl)); if (!($ssl == "tls" || $ssl == "ssl")) { $ssl = false; trigger_error('Invalid TLS/SSL value, on class POP3::connect()', 512); } } else { if (is_bool($ssl)) { $ssl = $ssl ? 'ssl' : false; } else { $ssl = false; trigger_error('Invalid TLS/SSL type value, on class POP3::connect()', 512); } } if (!is_int($timeout)) { $timeout = 30; trigger_error('Invalid timeout type value, on class POP3::connect()', 512); } if ($setver) { $proto = $ssl ? $ssl . '://' : ''; if (!($fp = fsockopen($proto . $iphost, $port, $err_num, $err_msg, $timeout))) { $setver = false; trigger_error('Response 1 error "' . $err_msg . '", on class POP3::connect()', 512); } else { stream_set_timeout($fp, $timeout); $rcv = fgets($fp, 1024); if (substr($rcv, 0, 3) != '+OK') { fclose($fp); $setver = false; trigger_error('Response 2 error "' . $rcv . '", on class POP3::connect()', 512); } if ($setver) { fputs($fp, "USER " . $user . "\r\n"); $rcv = fgets($fp, 1024); if (substr($rcv, 0, 3) != '+OK') { fclose($fp); $setver = false; trigger_error('Response 3 error "' . $rcv . '", on class POP3::connect()', 512); } } if ($setver) { fputs($fp, "PASS " . $pass . "\r\n"); $rcv = fgets($fp, 1024); if (substr($rcv, 0, 3) != '+OK') { fclose($fp); $setver = false; trigger_error('Response 4 error "' . $rcv . '", on class POP3::connect()', 512); } } if ($setver) { $setver = $fp; } } } return $setver; }
function send($subject) { $ret = false; if (is_string($subject)) { $subject = FUNC::str_clear($subject); $subject = trim($subject); if ($subject != "") { $this->_subject = $this->qpheader($subject); $ver = true; if (!($this->_toaddrs && count($this->_toaddrs) > 0)) { $ver = false; throw new Exception('You must set "To" e-mail address(es) using function "AddTo()", on class SMTP::send()', 512); } if (!($this->_atext || $this->_ahtml)) { $ver = false; throw new Exception('You must set the mail message using function(s) "Text() or/and Html()", on class SMTP::send()', 512); } if ($ver) { if ($this->_ccaddrs && count($this->_ccaddrs) > 0) { $clearcc1 = array(); foreach ($this->_ccaddrs as $ccaddrs1 => $ccname1) { $vercc1 = true; foreach ($this->_toaddrs as $toaddrs1 => $toname1) { if ($ccaddrs1 == $toaddrs1) { $vercc1 = false; } } if ($vercc1) { $clearcc1[$ccaddrs1] = $ccname1; } else { throw new Exception('The e-mail address "' . $ccaddrs1 . '" appear in To and Cc, on class SMTP::send()', 512); } } $this->_ccaddrs = $clearcc1; } if ($this->_bccaddrs && count($this->_bccaddrs) > 0) { $clearbcc1 = array(); foreach ($this->_bccaddrs as $bccaddrs1 => $bccname1) { $verbcc1 = true; foreach ($this->_toaddrs as $toaddrs2 => $toname2) { if ($bccaddrs1 == $toaddrs2) { $verbcc1 = false; } } if ($verbcc1) { $clearbcc1[$bccaddrs1] = $bccname1; } else { throw new Exception('The e-mail address "' . $bccaddrs1 . '" appear in To and Bcc, on class SMTP::send()', 512); } } $this->_bccaddrs = $clearbcc1; } if ($this->_bccaddrs && count($this->_bccaddrs) > 0 && $this->_ccaddrs && count($this->_ccaddrs) > 0) { $clearbcc2 = array(); foreach ($this->_bccaddrs as $bccaddrs2 => $bccname2) { $verbcc2 = true; foreach ($this->_ccaddrs as $ccaddrs2 => $ccname2) { if ($bccaddrs2 == $ccaddrs2) { $verbcc2 = false; } } if ($verbcc2) { $clearbcc2[$bccaddrs2] = $bccname2; } else { throw new Exception('The e-mail address "' . $bccaddrs2 . '" appear in Cc and Bcc, on class SMTP::send()', 512); } } $this->_bccaddrs = $clearbcc2; } $group = $alldom = array(); foreach ($this->_toaddrs as $toaddrs3 => $toname3) { $exp1 = explode('@', $toaddrs3); $group[$exp1[1]][] = $toaddrs3; $alldom[] = $toaddrs3; } if ($this->_ccaddrs && count($this->_ccaddrs) > 0) { foreach ($this->_ccaddrs as $ccaddrs3 => $ccname3) { $exp2 = explode('@', $ccaddrs3); $group[$exp2[1]][] = $ccaddrs3; $alldom[] = $ccaddrs3; } } if ($this->_bccaddrs && count($this->_bccaddrs) > 0) { foreach ($this->_bccaddrs as $bccaddrs3 => $bccname3) { $exp3 = explode('@', $bccaddrs3); $group[$exp3[1]][] = $bccaddrs3; $alldom[] = $bccaddrs3; } } $this->_content = $this->_writemsg(); $success = false; foreach ($this->_smtpconn as $conntype) { if (!$success) { if ($conntype == "local") { $success = $this->_sendtohost('127.0.0.1', $alldom, false); } elseif ($conntype == "relay") { if ($this->_relay) { $success = $this->_sendtohost($this->_relay['ip'], $alldom, true); } else { throw new Exception('You must set relay options with function "Relay()" in order to use relay connection, on class SMTP::send()', 512); } } elseif ($conntype == "client") { $back1 = $back2 = true; foreach ($group as $hostname => $domaddrs) { $back1 = $this->_sendtohost($hostname, $domaddrs, false); if (!$back1) { $back2 = false; } } $success = $back2; } } else { break; } } $ret = $success; } } else { throw new Exception('Invalid subject value, on class SMTP::send()', 512); } } else { throw new Exception('Invalid subject type value, on class SMTP::send()', 512); } return $ret; }
function mimetype($filename) { $retm = "application/octet-stream"; $mime = array('z' => "application/x-compress", 'xls' => "application/x-excel", 'gtar' => "application/x-gtar", 'gz' => "application/x-gzip", 'cgi' => "application/x-httpd-cgi", 'php' => "application/x-httpd-php", 'js' => "application/x-javascript", 'swf' => "application/x-shockwave-flash", 'tar' => "application/x-tar", 'tgz' => "application/x-tar", 'tcl' => "application/x-tcl", 'src' => "application/x-wais-source", 'zip' => "application/zip", 'kar' => "audio/midi", 'mid' => "audio/midi", 'midi' => "audio/midi", 'mp2' => "audio/mpeg", 'mp3' => "audio/mpeg", 'mpga' => "audio/mpeg", 'ram' => "audio/x-pn-realaudio", 'rm' => "audio/x-pn-realaudio", 'rpm' => "audio/x-pn-realaudio-plugin", 'wav' => "audio/x-wav", 'bmp' => "image/bmp", 'fif' => "image/fif", 'gif' => "image/gif", 'ief' => "image/ief", 'jpe' => "image/jpeg", 'jpeg' => "image/jpeg", 'jpg' => "image/jpeg", 'png' => "image/png", 'tif' => "image/tiff", 'tiff' => "image/tiff", 'css' => "text/css", 'htm' => "text/html", 'html' => "text/html", 'txt' => "text/plain", 'rtx' => "text/richtext", 'vcf' => "text/x-vcard", 'xml' => "text/xml", 'xsl' => "text/xsl", 'mpe' => "video/mpeg", 'mpeg' => "video/mpeg", 'mpg' => "video/mpeg", 'mov' => "video/quicktime", 'qt' => "video/quicktime", 'asf' => "video/x-ms-asf", 'asx' => "video/x-ms-asf", 'avi' => "video/x-msvideo", 'vrml' => "x-world/x-vrml", 'wrl' => "x-world/x-vrml"); if (is_string($filename)) { $filename = FUNC::str_clear($filename); $filename = trim($filename); if ($filename != "") { $expext = explode(".", $filename); if (count($expext) >= 2) { $extnam = strtolower($expext[count($expext) - 1]); if (isset($mime[$extnam])) { $retm = $mime[$extnam]; } } } else { trigger_error('Invalid parameter value, on class FUNC::mimetype()', 512); } } else { trigger_error('Invalid parameter type value, on class FUNC::mimetype()', 512); } return $retm; }