Home >Backend Development >PHP Tutorial >Use PHP to collect POP3 emails (3)_PHP tutorial
Application examples
The class for receiving emails via POP3 has been introduced in detail in the previous article. Let’s take a look at how to apply this class:
include("pop3.inc.php") ;
$host="pop.china.com";
$user="boss_ch";
$pass="026007";
$rec=new pop3($host,110,2 );
if (!$rec->open()) die($rec->err_str);
echo "open ";
if (!$rec->login($user , $pass)) die($rec->err_str);
echo "login";
if (!$rec->stat()) die($rec->err_str);
echo "Total ".$rec->messages." letters, total ".$rec->size." byte size
";
if ($rec->messages> ;0)
{
if (!$rec->listmail()) die($rec->err_str);
echo "There are the following letters:
";
for ($i=1;$i<=count($rec->mail_list);$i++)
{
echo "Letter".$rec->mail_list[$i][num]." Size: ".$rec->mail_list[$i][size]."
";
}
$rec->getmail(1);
echo "The content of the email header :
";
for ($i=0;$ihead);$i++)
echo htmlspecialchars($rec->head[$i])."
n";
echo "Email text:
";
for ($i=0;$ibody);$i++)
echo htmlspecialchars($rec->body[$i])."
n";
}
$rec->close();
?>
If you set debug in the pop3 class to true, you can also see the program and pop3 server How to communicate is more intuitive for the program being debugged.
Summary
From the above example, we can see that PHP is really a very powerful tool for website development, but we can also feel that PHP, as a hybrid language, faces objects Compared with other tools such as Java, there are still many regrettable aspects in the development. There are still many areas for improvement in the implementation of this pop class, and colleagues are welcome to provide guidance.
Author: Chen Junqing
If anyone wants to obtain the complete source code, please contact me: boss_ch@netease.com
Reprint: China.com