您好,欢迎访问一九零五行业门户网

PHP发送电子邮件类

send('收件人邮箱 ','主题','邮件正文内容'); 使用范例: $m= new sendm('smtp.yeah.net','testuser','testuserpwd',25,30); $m->send('a@coolmr.com ','测试邮件','这是一封邮件发送类的测试邮件,谢谢您的支持'); *************************************************************************************/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)!='250'){ 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:'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,'rcpt 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)=='250'){header(location:main_pro.php?act=msg&errors=on&msg=邮件发送成功!已成功提交至对方服务器!); }else{ header(location:main_pro.php?act=msg&errors=on&msg=很遗憾,邮件发送失败了!请检查邮件账户配置是否正确!); } } }?>
复制代码
发送电子邮件, php
其它类似信息

推荐信息