douqie6454 2014-08-03 17:35
浏览 114

imap_fetchbody()text / html section

I'm trying to develop a E-Mail-Provider-Script.

With the following function the E-Mails should be saved in the MySQL database directly, but my efforts to save only the TEXT / HTML section failed. What am I doing wrong( likely with imap_fetchbody() )?

function getEmailsImap($mailserver, $port, $user, $pass)
{
$imap = imap_open( "{" . $mailserver . ":" . $port . "}INBOX", $user, $pass );

    $check = imap_mailboxmsginfo($imap);
    $totalrows = imap_num_msg($imap);
    //iterate through all unread mails
    for ($index = 0; $index < $totalrows; $index++)
    {
        $header = imap_header($imap, $index + 1);
         //get mail subject
        $subject = $header->subject;
         //get mail sent date
        $date = date(DateTime::ISO8601 , $header->udate);
        //get email authors
        $email = "{$header->from[0]->mailbox}@{$header->from[0]->host}";
        //get body
        $body = imap_fetchbody($imap, $index+1, "1.2"); /*** I think this might be the mistake **/

        //get user
        $to = $header->to[0]->mailbox;
        $user = explode("@", $to)[0];

        $id = (int)mysql_fetch_row(mysql_query("SELECT `id` FROM `fd_emails` ORDER BY `id` DESC LIMIT 1"))[0];
            $new_id = $id+1;
        $sql = mysql_query("INSERT INTO `fd_emails` (`id`, `subject`, `text`, `sender`, `user`, `date`)
                                                   VALUES ('$new_id', '$subject', '$body', '$email', '$user', '$date');");

        imap_delete($imap, $index + 1);
    }
    //close connection to mailbox
    imap_expunge($imap);
    imap_close($imap);
    return true;
 }

Many thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongyi1015 2014-08-03 17:39
    关注

    As per the php documentation

    string imap_fetchbody ( resource $imap_stream , int $msg_number , string $section [, int $options = 0 ] )
    

    The number must have string type only. Using a integer type would raise an error.

    评论

报告相同问题?

悬赏问题

  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解