(第一次用PHP编程.有一些帮助.需要更多.)
目标:
从我的Gmail帐户中提取给定电子邮件地址的lastContactDate.希望回答这个问题,"我最后一次联系[人]是什么时候"
到目前为止我做了什么:
我做不到的事:
笔记:
研究:
迄今使用的代码:
/* connect to gmail */
$gmailhostname = '{imap.gmail.com:993/imap/ssl}';
$gmailusername = "___@gmail.com";
$gmailpassword = "___";
/* try to connect */
$conn = imap_open($gmailhostname,$gmailusername,$gmailpassword) or die('Cannot connect to Gmail: ' . imap_last_error());
$query = mysql_query("SELECT * FROM users");
while($row = mysql_fetch_array($query))
{
$findemail = $row["email"];
/* grab emails */
$emails = imap_search($conn,'FROM "'.$findemail.'"');
/* if emails are returned, cycle through …Run Code Online (Sandbox Code Playgroud) 我正在使用PHP 5.3.5并且我正在使用
$this->marubox=@imap_open($this->server,$this->username,$this->password);
Run Code Online (Sandbox Code Playgroud)
@符号应该使错误报告无声,但它没有,我确信错误发生在这一行.我希望我的应用程序能够识别问题本身并做出反应并且不会出现NOTICE错误,因为我的公司开发策略,我无法关闭整个PHP的错误报告.
没有@我得到:
imap_open()[function.imap-open]:无法打开流{pop3.seznam.cz:110/pop3}INBOX我得到:注意未知:身份验证失败(身份验证失败)(errflg = 1)
如果登录信息正常,则打开连接并且不会发生错误.
当imap_open没有设法连接时,我总是收到NOTICE错误,而且它正在弄乱我的JSON结果.请问如何沉默?
我尝试通过 PHP 打开 IMAP 连接
imap_open ("{localhost:993/ssl}", "username", "pwd")
Run Code Online (Sandbox Code Playgroud)
好的,这不能按预期工作,因为我使用的是自签名证书。但至少我得到了一个错误:
Warning .... Couldn't open stream
Run Code Online (Sandbox Code Playgroud)
所以我尝试
imap_open ("{localhost:993/ssl/novalidate-cert}", "username", "pwd")
Run Code Online (Sandbox Code Playgroud)
然后:什么都没有 - 白页 - 没有错误或警告,服务器日志中没有错误。
邮件服务器已正确配置 - 通过 Thunderbird 或 Outlook 在此端口上启用 ssl 加密进行连接没有问题。
我还尝试使用 imap_open 和 ssl 以及 novalidate-cert 连接到 127.0.0.1、主机名、IP 地址 - 一旦我添加 novalidate-cert 参数,这些试验都不起作用。我不知道为什么。
我还检查了 php_info:为 IMAP 启用了 SSL 并且 openssl 也处于活动状态。
如果我在没有 SSL 的情况下连接,一切正常。非常感谢您的帮助
我的邮箱里有很多电子邮件,上面有一些特定的标签,如"NR-Support",其中包含来自www.naveedramzan.com联系表格的电子邮件.
我开发了票务系统,现在它直接从联系表格中保存票务系统.
但是,我想将标记为NR-Support的所有旧电子邮件转换为该票务系统.
我试过imap_open但没有得到任何线索获得特定标签的电子邮件.
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'naveed.ramzan@gmail.com';
$password = 'abc123';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$emails = imap_search($inbox,'ALL');
if($emails) {
$output = '';
rsort($emails);
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';
$output.= '<div class="body">'.$message.'</div>';
}
echo $output;
}
imap_close($inbox);
Run Code Online (Sandbox Code Playgroud)