[PHP] How to use imap protocol to receive emails

little bottle
Release: 2023-04-06 06:34:01
forward
3365 people have browsed it

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;
}
?>
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!