【发布时间】:2011-12-30 18:35:06
【问题描述】:
当用户向我的电子邮件地址发送电子邮件时,我如何才能将他们的电子邮件文本/信息写入 mysql 表?所以基本上把一封新邮件的内容提取出来,写入mysql表中。
我试过了,但什么也没得到:
<?php
$imap = imap_open("{gmail.com}", "username", "password");
if( $imap ) {
//Check no.of.msgs
$num = imap_num_msg($imap)
//if there is a message in your inbox
if( $num >0 ) {
//read that mail recently arrived
echo imap_qprint(imap_body($imap, $num));
}
//close the stream
imap_close($imap);
}
?>
我们正在使用交换服务器..我是 coop 学生,所以我在这方面不是很先进。
我尝试了这个作为测试,看看它是否有效,登录 gmail 阅读电子邮件。没用。
<?php
// connect to the mailbox
$m_mail = imap_open("{mail.https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2}INBOX", "username", "password");
//get all messages
$m_search=imap_search ($m_mail, 'ALL ');
// Order results starting from newest message
rsort($m_search);
//loop through and do what's necessary
foreach ($m_search as $onem) {
//get imap header info for obj thang
$headers = imap_headerinfo($m_mail, $onem);
$head = imap_fetchheader($m_mail, $headers->Msgno);
$body = imap_body($m_mail, $headers->Msgno, FT_INTERNAL );
echo $body;
}
//purge messages (if necessary)
imap_expunge($m_mail);
//close mailbox
imap_close($m_mail);
?>
【问题讨论】:
-
1.你缺少';' a imap_num_msg($imap) 的结尾; 2. 确保你真的连接到你的服务器。如果您返回 $imap 可能是 FALSE,这意味着未连接 3. 确保您也指定了正确的服务器 - gmail.com 看起来关闭