POP3 and SMTP email sending and receiving programs

Source: Internet
Author: User
Tags socket
<? Php
If ($ EMAIL_INC) return;
$ EMAIL_INC = "defined ";
Define ("SmtpPort", 25 );
Class Pop3 {
Var $ subject; // email subject
Var $ from_email; // sender address
Var $ from_name; // sender's name
Var $ to_email; // recipient address
Var $ to_name; // recipient name
Var $ body; // email content
Var $ filename; // file name
Var $ socket; // The current socket
Var $ Line;
Var $ Status;
Function pop3_open ($ server, $ port)
{
$ This-> Socket = fsockopen ($ server, $ port );
If ($ this-> Socket <= 0 ){
Return false;
}
$ This-& gt; Line = fgets ($ this-& gt; Socket, 1024 );
$ This-> Status ["LASTRESULT"] = substr ($ this-> Line, 0, 1 );
$ This-> Status ["LASTRESULTTXT"] = substr ($ this-> Line, 0, 1024 );
If ($ this-> Status ["LASTRESULT"] <> "+") return false;
Return true;
}
Function pop3_user ($ user)
{
If ($ this-> Socket <0 ){
Return false;
}
Fputs ($ this-> Socket, "USER $ this-> userrn ");
$ This-& gt; Line = fgets ($ this-& gt; Socket, 1024 );
$ This-> Status ["LASTRESULT"] = substr ($ this-> Line, 0, 1 );
$ This-> Status ["LASTRESULTTXT"] = substr ($ this-> Line, 0, 1024 );
If ($ this-> Status ["LASTRESULT"] <> "+") return false;
Return true;
}
Function pop3_pass ($ pass)
{
Fputs ($ this-> Socket, "PASS $ passrn ");
$ This-& gt; Line = fgets ($ this-& gt; Socket, 1024 );
$ This-> Status ["LASTRESULT"] = substr ($ this-> Line, 0, 1 );
$ This-> Status ["LASTRESULTTXT"] = substr ($ this-> Line, 0, 1024 );
If ($ this-> Status ["LASTRESULT"] <> "+") return 0;
Return 1;
}
Function pop3_stat ()
{
Fputs ($ this-> Socket, "STATrn ");
$ This-& gt; Line = fgets ($ this-& gt; Socket, 1024 );
$ This-> Status ["LASTRESULT"] = substr ($ this-> Line, 0, 1 );
$ This-> Status ["LASTRESULTTXT"] = substr ($ this-> Line, 0, 1024 );
If ($ this-> Status ["LASTRESULT"] <> "+") return 0;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.