<?php
set_time_limit(0);
ignore_user_abort(true);
ini_set('max_execution_time', 0);
// 207.46.10.10:993 hotmail imap server
$s = "\r\n";
$proxy = '13.89.36.103'; // proxy
$port =53;
$fp = fsockopen($proxy, $port);
//socket_set_timeout($fp, 10, 0);
fputs($fp, "CONNECT 207.46.10.10:993 HTTP/1.1".$s.$s);
fputs($fp, "n1 login user@hotmail.com userpassword".$s);
fputs($fp, "n2 select Inbox".$s);
fputs($fp, "n3 UID FETCH 100289 BODY[]".$s);
fputs($fp, "n4 LOGOUT".$s.$s);
while(!feof($fp)){
$line = fgets($fp, 4000);
echo $line."\n";
}
fclose($fp);
?>
是否可以使用代理连接从使用PHP的imap服务器读取邮件
在没有代理 的情况下工作正常 如果有人可以帮助我,我不想使用卷曲
答案 0 :(得分:2)
<?php
set_time_limit(0);
ignore_user_abort(true);
ini_set('max_execution_time', 0);
$s = "\r\n";
$socket = stream_socket_client("tcp://128.199.105.86:3128", $errno, $errstr, 30);
if($socket) {
echo "con";
$buf = null;
$buff = null;
fwrite($socket, "CONNECT imap-mail.outlook.com:993 HTTP/1.1\r\n");
fwrite($socket,"Host: imap-mail.outlook.com:993\r\n");
fwrite($socket, "Proxy-Connection: Keep-Alive\r\n\r\n");
while(!feof($socket)){
$buf .= fgets($socket, 4096);
if(preg_match('/^http/i', $buf)){
break;
}
}
$modes = array(
STREAM_CRYPTO_METHOD_TLS_CLIENT,
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
);
$success = false;
foreach($modes as $mode) {
$success = stream_socket_enable_crypto($socket, true, $mode);
if ($success) {
echo "done";
break;
}
}
while(!feof($socket)){
$buf .= fgets($socket, 4096);
if(preg_match('/^\* ok/i', $buf)){
break;
}
}
echo $buf;
fclose($socket);
}
?>
工作版
答案 1 :(得分:0)
使用CONNECT
动词后,HTTP代理提供了一个哑管。由于您要连接到安全的IMAP服务,因此需要在建立连接后启用SSL / TLS。
对于某些搜索,看起来您可以在从PROXY服务器获得200
响应后使用stream_socket_enable_crypto。您很可能必须在使用stream_socket_enable_crypto
之前阅读响应,否则在读取意外数据时会抛出错误。
答案 2 :(得分:0)
<?php
set_time_limit(0);
ignore_user_abort(true);
ini_set('max_execution_time', 0);
$s = "\r\n";
$socket = stream_socket_client("tcp://61.19.250.51:3128", $errno, $errstr, 30);
if($socket) {
echo "con";
$buf = null;
fwrite($socket, "CONNECT imap-mail.outlook.com:993 HTTP/1.1\r\n");
fwrite($socket, "Proxy-Connection: Keep-Alive\r\n\r\n");
while (!feof($socket)) {
$buf .= fread($socket, 8190);
}
if(trim($buf)=="HTTP/1.1 200 Connection established"){
echo $buf;
stream_set_blocking ($socket, true);
if(!stream_socket_enable_crypto ($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)){
echo "not changed to encrypted mode";
}
}
fclose($socket);
}
?>
这个新代码但是当我为ssl模式选择过于开关时有不同的问题,函数stream_socket_enable_crypto()总是返回false我不知道为什么