有人可以告诉我以下代码是否有问题?或者如果问题与代码无关。
我似乎无法连接到邮件服务器,并且在执行代码期间,它在我的类文件中以Warning: imap_open(): Couldn't open stream {imap.one.com993}INBOX
错误响应。比前一个错误低Notice: Unknown: Host not found (#11001): imap.one.com993 (errflg=2) in Unknown on line 0
。
class email {
public $server;
public $username;
public $password;
public $port;
public $link;
public $status;
function connect($host, $port, $login, $pass){
$this->server = $host;
$this->username = $login;
$this->link = imap_open("{". $host . $port."}INBOX", $login, $pass);
if($this->link) {
$this->status = 'Connected';
} else {
$this->error[] = imap_last_error();
$this->status = 'Not connected';
}
}
}
索引文件:
<?php
$email = new email();
$email->connect("imap.one.com", "993", "email@address.com", "passwordString");
?
答案 0 :(得分:2)
您需要在主机和端口之间使用冒号(:
),因为您需要{imap.one.com:993}INBOX
,而不是{imap.one.com993}INBOX
。修复如下:
$this->link = imap_open("{". $host . ":" . $port."}INBOX", $login, $pass);
答案 1 :(得分:0)
你错过了冒号:
{{1}}
没有它,PHP认为主机是“imap.one.com993”,显然,它无法通过DNS检查。