- /***********************************************************************************
- Instructions for use:
- $m = new Sendm (' SMTP server address ', ' account ', ' Password ', port (int), timeout retry time (int));
- $m->send (' recipient mailbox ', ' Subject ', ' message body content ');
- Examples of Use:
- $m = new Sendm (' smtp.yeah.net ', ' testuser ', ' testuserpwd ', 25,30);
- $m->send (' a@coolmr.com ', ' Test mail ', ' This is a mail-sending class of test mail, 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)! = ' + ') {return false;}
- Fputs ($this->ms, ' auth login '. $this->ending);
- $RCP = $this->get_echo ();
- if (substr ($RCP, 0,3) = = ' 334 ') {$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, 0,3) = = ' + ') {header ("location:main_pro.php?act=msg&errors=on&msg= Mail sent successfully! Successfully submitted to the other server! "); } else{header ("location:main_pro.php?act=msg&errors=on&msg= very sorry, the Mail failed!" Please check the email account configuration is correct! "); }
- }
- }
- ?>
Copy Code
|