php - 无法连接:无法连接到 lyh-efz.ms-acdc.office.com,995:连接超时
问题描述
<?php
set_time_limit(3000);
$hostname = '{outlook.office365.com:993/imap/ssl}INBOX';
$username = '';//email address
$password = '';//password
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'SUBJECT "Log2.out file from Webcenter Prod"');
$max_emails = 1;
/* if emails are returned, cycle through each... */
if($emails) {
$count = 1;
/* begin output var */
$output = '';
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,1.1);
$structure = imap_fetchstructure($inbox,$email_number);
$attachments = array();
/* if any attachments found... */
if(isset($structure->parts) && count($structure->parts))
{
for($i = 0; $i < count($structure->parts); $i++)
{
$attachments[$i] = array(
'is_attachment' => false,
'filename' => '',
'name' => '',
'attachment' => ''
);
if($structure->parts[$i]->ifdparameters)
{
foreach($structure->parts[$i]->dparameters as $object)
{
if(strtolower($object->attribute) == 'filename')
{
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['filename'] = $object->value;
}
}
}
if($structure->parts[$i]->ifparameters)
{
foreach($structure->parts[$i]->parameters as $object)
{
if(strtolower($object->attribute) == 'name')
{
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['name'] = $object->value;
}
}
}
if($attachments[$i]['is_attachment'])
{
$attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1);
/* 3 = BASE64 encoding */
if($structure->parts[$i]->encoding == 3)
{
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
}
/* 4 = QUOTED-PRINTABLE encoding */
elseif($structure->parts[$i]->encoding == 4)
{
$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
}
}
}
}
/* iterate through each attachment and save it */
foreach($attachments as $attachment)
{
if($attachment['is_attachment'] == 1)
{
$filename = $attachment['name'];
if(empty($filename)) $filename = $attachment['filename'];
if(empty($filename)) $filename = time() . ".dat";
/* prefix the email number to the filename in case two emails
* have the attachment with the same file name.
*/
$fp = fopen("./" . $email_number . "-" . $filename, "w+");
fwrite($fp, $attachment['attachment']);
fclose($fp);
}
}
if($count = $max_emails) break;
/* output the email header information */
/* $output.= '<p><div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<p>Subject: <span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<p>From: <span class="from">'.$overview[0]->from.'</span>';
$output.= '<p>Date: <span class="date">on '.$overview[0]->date.'</span>';*/
//$output.= '</div>';
/* output the email body */
/*$output.= '<p>Message:<div class="body">'.$message.'';
$output.= '<p>attachment:'.$filename.'';
$output.= '<table><tr><hr size="1" width="100%%" noshade color="black" ></tr></table>';*/
}
echo $output;
}
/* close the connection */
imap_close($inbox);
?>
以上是我用来保存附件的代码。该代码在本地主机中运行良好,但是当我在服务器中运行它时出现以下错误
警告:imap_open():无法在第 9 行的 /opt/lampp/htdocs/AMSDASH/v1/index2.php 中打开流 {outlook.office365.com:995/imap/ssl/novalidate-cert}INBOX 无法连接:无法连接到 lyh-efz.ms-acdc.office.com,995:连接超时 注意:未知:无法连接到 lyh-efz.ms-acdc.office.com,995:连接超时(errflg =1) 在第 0 行的未知中
注意:未知:无法连接到 lyh-efz.ms-acdc.office.com,995:第 0 行未知中的连接超时(errflg=1)
注意:未知:无法连接到 lyh-efz.ms-acdc.office.com,995:第 0 行未知中的连接超时(errflg=1)
注意:未知:无法连接到 lyh-efz.ms-acdc.office.com,995:第 0 行未知中的连接超时(errflg=2)
非常感谢任何帮助。谢谢
解决方案
推荐阅读
- java - Spring-Boot:运行 spring-boot restful 程序失败
- unity3d - 使用 Unity Vimeo API 下载 Vimeo 视频以供离线使用
- java - 我如何检索孩子(姓名和列表图像)
- java - 使用 JNDI 的休眠数据源连接
- android - 为什么按下后退按钮时我的意图没有通过?
- c++ - C++ 类名冲突
- python - 替换python 3中的第一个字符串字符
- javascript - 如果表单验证为假(VueJS),则防止将数据发送到数据库/服务器
- php - 在 CodeIgniter 中删除文件夹
- spring-mvc - 嵌套异常是 javax.comm 中的 java.lang.NoClassDefFoundError 在部署 WAR 时使用 Srping MVC?