是否可以从我自己的域邮件中获取电子邮件?我想获取收件箱请帮忙,我现在正在使用IMAP,但它给了我ssl错误,如
MAIL.enlighten-energy.net的证书失败:服务器名称与证书不匹配:/ OU =域控制验证/ OU = PositiveSSL通配符/ CN = * .justhost.com
function fetch_gmail_inbox()
{
$res=array();
/* connect to gmail */
$hostname = '{imap.enlighten-energy.net:143/imap}';
$username = 'abc@enlighten-energy.net';
$password = '*******';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'UNSEEN');
/* if emails are returned, cycle through each... */
if($emails) {
/* 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 = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1));
$structure = imap_fetchstructure($inbox,$email_number);
if($structure->parts[0]->encoding == 3 ||$structure->encoding == 3 )
{
$message=imap_base64($message);
}
if($structure->parts[0]->encoding == 4 ||$structure->encoding == 4)
{
$message = imap_qprint($message);
}
$message2= quoted_printable_decode(imap_fetchbody($inbox,$email_number,0));
$date=explode(':',$message2);
$date2= date('d-m-Y h:i:s',strtotime($date[8].':00:00'));
if($overview[0]->subject=="USR:Site01_Comms Complete")
{
$res['date']=$date2;
$res['body']=$message;
}else
{
echo "not a correct mail";
}
}
return $res;
}
/* close the connection */
imap_close($inbox);
}
但是对我来说没有任何建议可以理解。提前谢谢
答案 0 :(得分:1)
MAIL.enlighten-energy.net的证书失败:服务器名称与证书不匹配:/ OU =域控制验证/ OU = PositiveSSL通配符/ CN = * .justhost.com
如果您了解SSL / TLS,则错误消息实际上非常清楚:
imap.enlighten-energy.net
(这是mail.enlighten-energy.net
的cname)*.justhost.com
*.justhost.com
与imap.enlighten-energy.net
不匹配,因此它不会信任证书,因为如果它只信任任何证书,那么该连接将对中间人攻击开放,这可能会失败加密。总结:如果您要为IMAP服务器使用自己的域名,则必须使用您自己域的证书设置此服务器。如果这是多个主机之间的共享服务器,并且您无法访问此服务器的配置,则无法执行此操作。
答案 1 :(得分:0)
找到解决方案,我必须使用
$hostname = '{mail.enlighten-energy.net:143/imap/novalidate-cert}INBOX';
而不是
$hostname = '{imap.enlighten-energy.net:143/imap}';
喜欢,这是完整的解决方案
function fetch_gmail_inbox()
{
$res=array();
/* connect to gmail */
$hostname = '{mail.enlighten-energy.net:143/imap/novalidate-cert}INBOX';
$username = Yii::app()->getModule('user')->get_config('datalogger_email');
$password = Yii::app()->getModule('user')->get_config('datalogger_email_pwd');
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'UNSEEN');
/* if emails are returned, cycle through each... */
if($emails) {
/* 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 = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1));
$structure = imap_fetchstructure($inbox,$email_number);
if($structure->parts[0]->encoding == 3 ||$structure->encoding == 3 )
{
$message=imap_base64($message);
}
if($structure->parts[0]->encoding == 4 ||$structure->encoding == 4)
{
$message = imap_qprint($message);
}
$message2= quoted_printable_decode(imap_fetchbody($inbox,$email_number,0));
$date=explode(':',$message2);
$date2= date('d-m-Y h:i:s',strtotime($date[8].':00:00'));
if($overview[0]->subject=="USR:Site01_Comms Complete")
{
$res['date']=$date2;
$res['body']=$message;
}
}
return $res;
}
/* close the connection */
imap_close($inbox);
}