使用PHP脚本处理传入的电子邮件
作者:互联网
所以我想弄清楚如何发送电子邮件到一个地址,例如,something @ whatever.com而不是电子邮件到那里它将被发送或转发到我创建的脚本,以阅读电子邮件的内容并将内容存储到数据库中.有关如何在PHP中执行此操作的任何建议?
谢谢!
解决方法:
这里有一些代码可以用来帮助你:
// set user to check
$strUser = "username";
$strPassword = "password";
// open
$hMail = imap_open ("{mail.yourdomain.com:143/notls}INBOX", "$strUser", "$strPassword");
// get headers
$aHeaders = imap_headers( $hMail );
// get message count
$objMail = imap_mailboxmsginfo( $hMail );
// 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
}
// delete message
imap_delete( $hMail, $idxMsg );
}
// expunge deleted messages
imap_expunge( $hMail );
// close
imap_close( $hMail );
标签:php,cron,email,cpanel 来源: https://codeday.me/bug/20191004/1854518.html