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 = 'zekai'; $mailPass = 'password'; $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!