这是我正在使用的代码:
if (!($fp = fsockopen('ssl://imap.gmail.com', '993', $errno, $errstr, 15)))
echo "Could not connect to host";
$server_response = fread($fp, 256);
echo $server_response;
fwrite($fp, "C01 CAPABILITY"."\r\n");
while (!feof($fp)) {
echo fgets($fp, 256);
}
Run Code Online (Sandbox Code Playgroud)
我收到了第一个回复:
OK Gimap ready for requests from xx.xx.xx.xx v3if9968808ibd.15
Run Code Online (Sandbox Code Playgroud)
但随后页面超时.我搜索了stream_set_blocking,stream_set_timeout,stream_select,fread等,但无法让它工作.我需要读取服务器发送的所有数据,然后继续执行其他命令(我将使用imap检索电子邮件).
谢谢
这是一个从imap服务器下载附件文件的代码.几乎所有文件类型(pdf,doc,xls等)都正确下载,而某些zip文件会出现以下错误:
"存档格式未知或已损坏"
码:
//data from imap server
$name = "xyz 123.zip";
$type = "APPLICATION";
$subtype = "ZIP";
$encoding = "BASE64";
$body = imap_base64($data);
header('Content-Description: File Transfer');
header('Content-Type: '. $type .'/'. $subtype);
header('Content-Disposition: attachment; filename='.$name);
header('Content-Transfer-Encoding: '.$encoding);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_clean();
flush();
echo $body;
Run Code Online (Sandbox Code Playgroud)
此外,如果我回显数据并使用以下方法将其转换为文件:
http://www.motobit.com/util/base64-decoder-encoder.asp
正在正确下载该文件.因此从服务器获取文件没有问题.我哪里错了?