The PHP mail feature we have seen before is good or not.

Source: Internet
Author: User
P? /* Pop3Functions. SmtpFunctions. [Addedlater, goingtosplit] Forarealexampletakealookat: http://www.triple-it.nl/pop3/IhavejuststartedtoexploretheworldofPHP3,soexcus

P> /* Pop3 Functions.
Smtp Functions. [Added later, going to split]

For a real example take a look:
Http://www.triple-it.nl/pop3/

I have just started to convert e the world of PHP3,
So excuse (and correct me :) if I'm doing something wrong.

Unk. (rgroesb@triple-it.nl)
*/

Function pop3_open ($ server, $ port)
{
Global $ POP3_GLOBAL_STATUS;

$ Pop3 = fsockopen ($ server, $ port );
If ($ pop3 <= 0) return 0;

$ Line = fgets ($ pop3. 1024 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] <> "+") return 0;

Return $ pop3;
}

Function pop3_user ($ pop3, $ user)
{
Global $ POP3_GLOBAL_STATUS;

Fputs ($ pop3, "USER $ user \ r \ n ");
$ Line = fgets ($ pop3. 1024 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] <> "+") return 0;

Return 1;
}

Function pop3_pass ($ pop3, $ pass)
{
Global $ POP3_GLOBAL_STATUS;

Fputs ($ pop3, "PASS $ pass \ r \ n ");
$ Line = fgets ($ pop3. 1024 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] <> "+") return 0;

Return 1;
}

Function pop3_stat ($ pop3)
{
Global $ POP3_GLOBAL_STATUS;

Fputs ($ pop3, "STAT \ r \ n ");
$ Line = fgets ($ pop3. 1024 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] <> "+") return 0;

If (! Eregi ("+ OK (. *) (. *)", $ line, $ regs ))
Return 0;

Return $ regs [1];
}

Function pop3_list ($ pop3)
{
Global $ POP3_GLOBAL_STATUS;

Fputs ($ pop3, "LIST \ r \ n ");
$ Line = fgets ($ pop3. 1024 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] <> "+") return 0;

$ I = 0;
While (substr ($ line = fgets ($ pop3, 1024), 0, 1) <> ".")
{
$ Articles [$ I] = $ line;
$ I ++;
}
$ Articles ["count"] = $ I;

Return $ articles;
}

Function pop3_retr ($ pop3, $ nr)
{
Global $ POP3_GLOBAL_STATUS;

Fputs ($ pop3, "RETR $ nr \ r \ n ");
$ Line = fgets ($ pop3. 1024 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] <> "+") return 0;

While (substr ($ line = fgets ($ pop3, 1024), 0, 1) <> ".")
{
$ Data [$ I] = $ line;
$ I ++;
}
$ Data ["count"] = $ I;

Return $ data;
}

Function pop3_dele ($ pop3, $ nr)
{
Global $ POP3_GLOBAL_STATUS;

Fputs ($ pop3, "DELE $ nr \ r \ n ");
$ Line = fgets ($ pop3. 1024 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] <> "+") return 0;


Return 1;
}

Function pop3_quit ($ pop3)
{
Global $ POP3_GLOBAL_STATUS;

Fputs ($ pop3, "QUIT \ r \ n ");
$ Line = fgets ($ pop3. 1024 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ POP3_GLOBAL_STATUS [$ pop3] ["LASTRESULT"] <> "+") return 0;

Return 1;
}

Function smtp_open ($ server, $ port)
{
Global $ SMTP_GLOBAL_STATUS;

$ Smtp = fsockopen ($ server, $ port );
If ($ smtp <0) return 0;

$ Line = fgets ($ smtp, 1024 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] <> "2") return 0;

Return $ smtp;
}


Function smtp_helo ($ smtp)
{
Global $ SMTP_GLOBAL_STATUS;

/* 'Localhost' always works [Unk] */
Fputs ($ smtp, "helo localhost \ r \ n ");
$ Line = fgets ($ smtp, 1024 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] <> "2") return 0;

Return 1;
}

Function smtp_ehlo ($ smtp)
{
Global $ SMTP_GLOBAL_STATUS;

/* Well, let's use "helo" for now... Until we need
Extra func's [Unk]
*/
Fputs ($ smtp, "helo localhost \ r \ n ");
$ Line = fgets ($ smtp, 1024 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] <> "2") return 0;

Return 1;
}


Function smtp_mail_from ($ smtp, $ from)
{
Global $ SMTP_GLOBAL_STATUS;

Fputs ($ smtp, "mail from: <$ from> \ r \ n ");
$ Line = fgets ($ smtp, 1024 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] <> "2") return 0;

Return 1;
}

Function smtp_rcpt_to ($ smtp, $)
{
Global $ SMTP_GLOBAL_STATUS;

Fputs ($ smtp, "rcpt to: <$ to> \ r \ n ");
$ Line = fgets ($ smtp, 1024 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] <> "2") return 0;

Return 1;
}

Function smtp_data ($ smtp, $ subject, $ data)
{
Global $ SMTP_GLOBAL_STATUS;

Fputs ($ smtp, "DATA \ r \ n ");
$ Line = fgets ($ smtp, 1024 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] <> "3") return 0;

Fputs ($ smtp, "Mime-Version: 1.0 \ r \ n ");
Fputs ($ smtp, "Subject: $ subject \ r \ n ");
Fputs ($ smtp, "$ data \ r \ n ");
Fputs ($ smtp, ". \ r \ n ");
$ Line = fgets ($ smtp, 1024 );
If (substr ($ line, 0, 1) <> "2 ")
Return 0;

Return 1;
}

Function smtp_quit ($ smtp)
{
Global $ SMTP_GLOBAL_STATUS;

Fputs ($ smtp, "QUIT \ r \ n ");
$ Line = fgets ($ smtp, 1024 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] = substr ($ line, 0, 1 );
$ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULTTXT"] = substr ($ line, 0, 1024 );

If ($ SMTP_GLOBAL_STATUS [$ smtp] ["LASTRESULT"] <> "2") return 0;

Return 1;
}


/*
$ Pop3 = pop3_open ("localhost", "110 ");
If (! $ Pop3 ){
Printf ("[ERROR] Failed to connect to localhost
\ N ");
Return 0;
}

If (! Pop3_user ($ pop3, "unk ")){
Printf ("[ERROR] Username failed!
\ N ");
Return 0;
}

If (! Pop3_pass ($ pop3, "secret ")){
Printf ("[ERROR] PASS failed!
\ N ");
Return 0;
}

$ Articles = pop3_list ($ pop3 );
If (! $ Articles ){
Printf ("[ERROR] LIST failed!
\ N ");
Return 0;
}

For ($ I = 1; $ I <$ articles ["count"] + 1; $ I ++)
{
Printf ("I = $ I
\ N ");
$ Data = pop3_retr ($ pop3, $ I );
If (! $ Data ){
Printf ("data goes wrong on '$ I'
\ N ");
Return 0;
}

For ($ j = 0; $ j <$ data ["count"]; $ j ++)
{
Printf ("$ data [$ j]
\ N ");
}
}
*/


?>

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.