我写了一个简单的3行代码,用于通过imap-php连接到gmail。我使用000webhost来运行它。但当我试图打开它时,它会继续加载,并在一段时间后显示"加载页面有问题"或"没有收到数据",就好像gmail服务器没有响应一样!!有什么建议吗?问题出在哪里?
$hostname = "{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox";
$username = 'abc@gmail.com';
$password = "abc123";
$inbox = imap_open($hostname,$username,$password)or die('Cannot connect to Gmail: ' . imap_last_error());
$server_name = "imap.gmail.com";
$account_name = "email@mydomain.com";
$account_pwd = "my_account_password";
$inbox = imap_open("{".$server_name.":993/imap/ssl/novalidate-cert}INBOX",
$account_name, $account_pwd) OR error_imap_mail("Unable To Open Imap
Connection","Imap Failure",imap_errors());
function error_imap_mail($subject,$messagetext,$errors) {
global $report_email;
$mailfrom = "support@mydomain.com";
$mailsubject = "$subject";
$mailbody = "$messagetextnn";
if (count($errors) >0) {
if (substr($errors[0],0,8) <> "[IN-USE]") {
array_reverse($errors);
foreach ($errors as $key=>$value) {
$mailbody .= "nErr No.".$key." Error:".$value;
}
foreach ($report_email as $value) {
mail($value, $mailsubject, $mailbody, "From: $mailfrom");
}
}#if (substr($err_array[0],0,8) <> "[IN-USE]") {
}#if (count($errors) >0) {
exit;
}
如果连接失败,请让脚本向您发送错误信息。
你在Gmail的帐户设置中打开IMAP了吗?
试试这个:
$hostname = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$username = 'abc@gmail.com';
$password = "abc123";
$inbox = imap_open($hostname,$username,$password)or die('Cannot connect to Gmail: ' . imap_errors());
此外,请确保通过GMail设置为您的帐户启用IMAP。