如何从电子邮件中提取内容并将其写入mysql表? [英] how can I pull out the contents from an email and write them in a mysql table?

查看:125
本文介绍了如何从电子邮件中提取内容并将其写入mysql表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户电子邮件发送到我的电子邮件地址,电子邮件文本/信息将被写入到mysql表中,我该怎么做?所以基本上提取一个新的电子邮件的内容并将它们写入mysql表。

How can I make it so when a user email's to my email address their email text/information is written into a mysql table? So basically extract the contents of a new email and write them into mysql table.

我尝试过这个但是我什么也没有:

I tried this but I get nothing:

<?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学生,所以我不是很先进

We are using an exchange server..I am a coop student so I am not really advanced at this.

我试过这个测试,看看它是否有效,登录Gmail读取电子邮件。它没有工作。

I tried this as a test to see if it works, logging in gmail to read email. It didnt work.

<?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&ltmpl=default&ltmplcache=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);

?>


推荐答案

使用IMAP功能。必要时设置另一个电子邮件帐户。以下是示例代码:

use IMAP functions for that. Set up another email account if necessary. Here's the example code:

// connect to the mailbox
$m_mail = imap_open("{mail.YOURHOST.com:993/imap/ssl/novalidate-cert}INBOX", "address@YOURHOST.com", "YOURPASSWORD");

//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 );

    //
   DO WHAT YOU NEED TO DO HERE - insert to the database, etc

}

//purge messages (if necessary)
imap_expunge($m_mail);

//close mailbox 
imap_close($m_mail);

这篇关于如何从电子邮件中提取内容并将其写入mysql表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆