function _sendtohost($hname, $arrto, $isrelay) { $ret = false; if ($hname == "localhost") { $ret = mail($this->_content['header']['to'], $this->_subject, implode('', $this->_content['body']), $this->_content['header']['local']); if (!$ret) { $ret = $this->_sendtoip('127.0.0.1', $arrto, $isrelay); } } else { if ($isrelay) { $ret = $this->_sendtoip($hname, $arrto, $isrelay); } else { if (FUNC::is_ipv4($hname)) { $ret = $this->_sendtoip($hname, $arrto, $isrelay); } else { $resmx = FUNC::is_win() ? FUNC::getmxrr_win($hname, $mxhost) : getmxrr($hname, $mxhost); $iparr = array(); if ($resmx) { foreach ($mxhost as $hostname) { $iphost = gethostbyname($hostname); if ($iphost != $hname && FUNC::is_ipv4($iphost) && !isset($iparr[$iphost])) { $iparr[$iphost] = $iphost; } } } else { $iphost = gethostbyname($hname); if ($iphost != $hname && FUNC::is_ipv4($iphost)) { $iparr[$iphost] = $iphost; } } if (count($iparr) > 0) { foreach ($iparr as $ipaddr) { if ($ret = $this->_sendtoip($ipaddr, $arrto, $isrelay)) { break; } } } else { throw new Exception('Can not find any valid ip address for hostname "' . $hname . '", on class SMTP::_sendtohost()', 512); } } } } return $ret; }
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; }