- /*************************************** **************************************** ****
-
- Instructions for use:
-
- $ M = new SendM ('smtp server address', 'account', 'password', Port (int), timeout retry time (int ));
- $ M-> Send ('recipient mailbox ', 'topic', 'Email body content ');
-
- Example:
-
- $ M = new SendM ('smtp .yeah.net ', 'testuser', 'testuserpwd', 25, 30 );
- $ M-> Send ('a @ coolmr.com ', 'Test mail',' this is a test email for mail sending. thank you for your support ');
-
- **************************************** **************************************** *****/
- Class SendM {
- Private $ Mailhost, $ Mailuser, $ Mailpwd, $ Mailport, $ Mailtimeout, $ ms, $ ending = "\ r \ n", $ endingc = "\ n ";
- Function _ construct ($ Mailhost, $ Mailuser, $ Mailpwd, $ Mailport, $ Mailtimeout ){
- $ This-> Mailhost = $ Mailhost;
- $ This-> Mailuser = $ Mailuser;
- $ This-> Mailpwd = $ Mailpwd;
- $ This-> Mailport = $ Mailport;
- $ This-> Mailtimeout = $ Mailtimeout;
- $ This-> ConnectSmtpServer ();
- }
- Private function ConnectSmtpServer (){
-
- If (! Is_string ($ this-> Mailhost) {settype (trim ($ this-> Mailhost), "string ");}
-
- If (! Is_integer ($ this-> Mailport) {settype (trim ($ this-> Mailport), "integer ");}
-
- If (! Is_integer ($ this-> Mailtimeout) {settype (trim ($ this-> Mailtimeout), "integer ");}
-
- $ This-> ms = @ fsockopen ($ this-> Mailhost, $ this-> Mailport, $ this-> errorno, $ this-> errorstr, $ this-> Mailtimeout );
-
- If (substr (PHP_ OS, 0, 3 )! = "WIN") {stream_set_timeout ($ this-> ms, $ this-> Mailtimeout, 0 );}
-
- $ Rcp = $ this-> get_echo ();
-
- Fputs ($ this-> ms, "ehlo bobo". $ this-> ending );
-
- $ Rcp = $ this-> get_echo ();
- If (substr ($ rcp, 0, 3 )! = '20140901') {return false ;}
-
- Fputs ($ this-> ms, 'auth login'. $ this-> ending );
-
- $ Rcp = $ this-> get_echo ();
-
- If (substr ($ rcp, 334) = '000000') {$ this-> Auth ($ this-> Mailuser, $ this-> Mailpwd );} else {return false ;}}
-
- Private function Auth ($ Mailuser, $ Mailpwd ){
-
- $ This-> Mailuseren = base64_encode ($ Mailuser); $ this-> Mailpwden = base64_encode ($ Mailpwd );
-
- Fputs ($ this-> ms, $ this-> Mailuseren. $ this-> ending );
-
- $ Rcp = $ this-> get_echo ();
-
- Fputs ($ this-> ms, $ this-> Mailpwden. $ this-> ending );
-
- $ Rcp = $ this-> get_echo ();}
-
- Private function get_echo (){
- $ Edata = ""; while ($ estr = @ fgets ($ this-> ms, 600) {$ edata. = $ estr;
-
- If (substr ($ estr, 3, 1) = "") {break ;}}
- Return $ edata ;}
- Public function Send ($ to, $ subject, $ connect ){
- $ Host = explode ('.', $ this-> Mailhost );
- $ Fromaddress = $ this-> Mailuser. '@'. $ host [1]. '.'. $ host [2];
- Fputs ($ this-> ms, 'mail from: <'. $ fromaddress.'> '. $ this-> ending );
-
- $ Rcp = $ this-> get_echo ();
-
- Fputs ($ this-> ms, 'rcpt to: <'. $ to.'> '. $ this-> ending );
-
- $ Rcp = $ this-> get_echo ();
-
- Fputs ($ this-> ms, 'data'. $ this-> ending );
-
- $ Rcp = $ this-> get_echo ();
-
- Fputs ($ this-> ms, "to: $ to". $ this-> endingc );
-
- Fputs ($ this-> ms, "from: $ fromaddress". $ this-> endingc );
- Fputs ($ this-> ms, "subject: $ subject". $ this-> endingc. $ this-> endingc );
-
- Fputs ($ this-> ms, "$ connect". $ this-> endingc );
-
- Fputs ($ this-> ms, '.'. $ this-> ending );
- $ Rcp = $ this-> get_echo (); if (substr ($ rcp, 250) = '000000') {header ("Location: main_pro.php? Act = msg & errors = on & msg = email sent successfully! Submitted to the recipient's server! ");} Else {header (" Location: main_pro.php? Act = msg & errors = on & msg = sorry, the email failed to be sent! Check whether the email account configuration is correct! ");}
- }
- }
- ?>
|