How can I make it so when I e-mail for e.g. news@example.com text/information of the e-mail is written into a mysql table? It would extract the contents of a new email and write them into MySQL table. This table manages news articles on the website, so in the MySQL columns:
"content" is the body of the message
"caption" is the title of the news article
"snippet" is the title that will appear in a "Latest News" block
"uri"
"date" is the date the article is posted.
"
$subject = caption
= uri
$message = content
= snippet(first two lines of content)
$date = date (in Unix timestamp)
The table is named bx_news_entries manages the news articles visibly.
I researched and saw a user who posted this on stackoverflow who's code looked like so:
<?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);
}
?>
We are using an exchange server..I am a coop student so I am not really advanced at this.
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<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);
?>
I have the code imagined in my head, i just need to bring it to fruition.
Can somebody assist me with this please?