使用php脚本获取电子邮件的主题
我有以下脚本,它基本上由 cron 作业运行来检查电子邮件地址、获取消息正文并将其插入数据库。
我需要改变它才能获得主题,但我不知道如何......任何帮助都会很棒。
$aHeaders = imap_headers( $hMail );
// get message count
$objMail = imap_mailboxmsginfo( $hMail );
if($objMail != NULL)
{
// process messages
for( $idxMsg = 1; $idxMsg <= $objMail->Nmsgs; $idxMsg++ )
{
// get header info
$objHeader = imap_headerinfo( $hMail, $idxMsg );
// get from object array
$aFrom = $objHeader->from;
// process headers
for( $idx = 0; $idx < count($aFrom); $idx++ )
{
// get object
$objData = $aFrom[ $idx ];
// get email from
$strEmailFrom = $objData->mailbox . "@" . $objData->host;
// do some stuff here
$bodyMessage = imap_body($hMail,$idxMsg);//displays full
I have the following script which is basically run by a cron job to check an e-mail address, get the body of the message and insert it into the database.
I need to alter it to get the subject also, and I can't figure out how... any help would be great.
$aHeaders = imap_headers( $hMail );
// get message count
$objMail = imap_mailboxmsginfo( $hMail );
if($objMail != NULL)
{
// process messages
for( $idxMsg = 1; $idxMsg <= $objMail->Nmsgs; $idxMsg++ )
{
// get header info
$objHeader = imap_headerinfo( $hMail, $idxMsg );
// get from object array
$aFrom = $objHeader->from;
// process headers
for( $idx = 0; $idx < count($aFrom); $idx++ )
{
// get object
$objData = $aFrom[ $idx ];
// get email from
$strEmailFrom = $objData->mailbox . "@" . $objData->host;
// do some stuff here
$bodyMessage = imap_body($hMail,$idxMsg);//displays full
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您获取
from
的行之后:After the line where you get
from
:在第一个 for 循环内,
http://php.net/manual/en/function .imap-headerinfo.php
inside the first for loop,
http://php.net/manual/en/function.imap-headerinfo.php