Home  >  Article  >  Backend Development  >  [PHP] How to use imap protocol to receive emails

[PHP] How to use imap protocol to receive emails

little bottle
little bottleforward
2019-04-19 15:05:463425browse

The PHPMail class is a very powerful class that can send emails, but in fact, the bottom layer uses the mail() function to send emails. Now we need to receive emails in real time, mainly to determine whether the email has been sent and whether it can be received successfully. Therefore, we use the pop3 protocol to collect emails and obtain the emails. The program is as follows:

<?php

$mailServer="mail.staff.sina.com.cn";

$mailLink="{mail.staff.sina.com.cn:995/pop3/ssl}INBOX";

$mailUser = &#39;zekai&#39;; 

$mailPass = &#39;password&#39;; 

$stream = @imap_open($mailLink,$mailUser,$mailPass); 

$totalrows = imap_num_msg($stream);

var_dump($totalrows);

for($i=$totalrows;$i>=$totalrows;$i--)
{
    $headers = @imap_header($stream, $i);
    $mail_header= imap_headerinfo($stream, $i);
    var_dump ($mail_header);die;
    $subject = $mail_header->subject;
    $subject=decode_mime($subject);
    echo $subject;die;
}
?>

Related tutorials: PHP video tutorial

The above is the detailed content of [PHP] How to use imap protocol to receive emails. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete