<?php if(version_compare(PHP_VERSION,'5.0.0','<'))exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");class PHPMailer{public $Priority=3;public $CharSet='iso-8859-1';public $ContentType='text/plain';public $Encoding='8bit';public $ErrorInfo='';public $From='root@localhost';public $FromName='Root User';public $Sender='';public $Subject='';public $Body='';public $AltBody='';public $WordWrap=0;public $Mailer='mail';public $Sendmail='/usr/sbin/sendmail';public $PluginDir='';public $ConfirmReadingTo='';public $Hostname='';public $MessageID='';public $Host='localhost';public $Port=25;public $Helo='';public $SMTPSecure='';public $SMTPAuth=false;public $Username='';public $Password='';public $Timeout=10;public $SMTPDebug=false;public $SMTPKeepAlive=false;public $SingleTo=false;public $SingleToArray=array();public $LE="\n";public $DKIM_selector='phpmailer';public $DKIM_identity='';public $DKIM_domain='';public $DKIM_private='';public $action_function='';public $Version='5.1';private $smtp=NULL;private $to=array();private $cc=array();private $bcc=array();private $ReplyTo=array();private $all_recipients=array();private $attachment=array();private $CustomHeader=array();private $message_type='';private $boundary=array();protected $language=array();private $error_count=0;private $sign_cert_file="";private $sign_key_file="";private $sign_key_pass="";private $exceptions=false;const STOP_MESSAGE=0;const STOP_CONTINUE=1;const STOP_CRITICAL=2;public function __construct($exceptions=false){$this->exceptions=($exceptions==true);}public function IsHTML($ishtml=true){if($ishtml){$this->ContentType='text/html';}else{$this->ContentType='text/plain';}}public function IsSMTP(){$this->Mailer='smtp';}public function IsMail(){$this->Mailer='mail';}public function IsSendmail(){if(!stristr(ini_get('sendmail_path'),'sendmail')){$this->Sendmail='/var/qmail/bin/sendmail';}$this->Mailer='sendmail';}public function IsQmail(){if(stristr(ini_get('sendmail_path'),'qmail')){$this->Sendmail='/var/qmail/bin/sendmail';}$this->Mailer='sendmail';}public function AddAddress($address,$name=''){return $this->AddAnAddress('to',$address,$name);}public function AddCC($address,$name=''){return $this->AddAnAddress('cc',$address,$name);}public function AddBCC($address,$name=''){return $this->AddAnAddress('bcc',$address,$name);}public function AddReplyTo($address,$name=''){return $this->AddAnAddress('ReplyTo',$address,$name);}private function AddAnAddress($kind,$address,$name=''){if(!preg_match('/^(to|cc|bcc|ReplyTo)$/',$kind)){echo 'Invalid recipient array: '.$kind;return false;}$address=trim($address);$name=trim(preg_replace('/[\r\n]+/','',$name));if(!self::ValidateAddress($address)){$this->SetError($this->Lang('invalid_address').': '.$address);if($this->exceptions){throw new phpmailerException($this->Lang('invalid_address').': '.$address);}echo $this->Lang('invalid_address').': '.$address;return false;}if($kind!='ReplyTo'){if(!isset($this->all_recipients[strtolower($address)])){array_push($this->$kind,array($address,$name));$this->all_recipients[strtolower($address)]=true;return true;}}else{if(!array_key_exists(strtolower($address),$this->ReplyTo)){$this->ReplyTo[strtolower($address)]=array($address,$name);return true;}}return false;}public function SetFrom($address,$name='',$auto=1){$address=trim($address);$name=trim(preg_replace('/[\r\n]+/','',$name));if(!self::ValidateAddress($address)){$this->SetError($this->Lang('invalid_address').': '.$address);if($this->exceptions){throw new phpmailerException($this->Lang('invalid_address').': '.$address);}echo $this->Lang('invalid_address').': '.$address;return false;}$this->From=$address;$this->FromName=$name;if($auto){if(empty($this->ReplyTo)){$this->AddAnAddress('ReplyTo',$address,$name);}if(empty($this->Sender)){$this->Sender=$address;}}return true;}public static function ValidateAddress($address){if(function_exists('filter_var')){if(filter_var($address,FILTER_VALIDATE_EMAIL)===FALSE){return false;}else{return true;}}else{return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/',$address);}}public function Send(){try{if((count($this->to)+count($this->cc)+count($this->bcc))<1){throw new phpmailerException($this->Lang('provide_address'),self::STOP_CRITICAL);}if(!empty($this->AltBody)){$this->ContentType='multipart/alternative';}$this->error_count=0;$this->SetMessageType();$header=$this->CreateHeader();$body=$this->CreateBody();if(empty($this->Body)){throw new phpmailerException($this->Lang('empty_message'),self::STOP_CRITICAL);}if($this->DKIM_domain&&$this->DKIM_private){$header_dkim=$this->DKIM_Add($header,$this->Subject,$body);$header=str_replace("\r\n","\n",$header_dkim).$header;}switch($this->Mailer){case 'sendmail':return $this->SendmailSend($header,$body);case 'smtp':return $this->SmtpSend($header,$body);default:return $this->MailSend($header,$body);}}catch(phpmailerException$e){$this->SetError($e->getMessage());if($this->exceptions){throw $e;}echo $e->getMessage()."\n";return false;}}protected function SendmailSend($header,$body){if($this->Sender!=''){$sendmail=sprintf("%s -oi -f %s -t",escapeshellcmd($this->Sendmail),escapeshellarg($this->Sender));}else{$sendmail=sprintf("%s -oi -t",escapeshellcmd($this->Sendmail));}if($this->SingleTo===true){foreach($this->SingleToArray as $key=>$val){if(!@$mail=popen($sendmail,'w')){throw new phpmailerException($this->Lang('execute').$this->Sendmail,self::STOP_CRITICAL);}fputs($mail,"To: ".$val."\n");fputs($mail,$header);fputs($mail,$body);$result=pclose($mail);$isSent=($result==0)?1:0;$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);if($result!=0){throw new phpmailerException($this->Lang('execute').$this->Sendmail,self::STOP_CRITICAL);}}}else{if(!@$mail=popen($sendmail,'w')){throw new phpmailerException($this->Lang('execute').$this->Sendmail,self::STOP_CRITICAL);}fputs($mail,$header);fputs($mail,$body);$result=pclose($mail);$isSent=($result==0)?1:0;$this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);if($result!=0){throw new phpmailerException($this->Lang('execute').$this->Sendmail,self::STOP_CRITICAL);}}return true;}protected function MailSend($header,$body){$toArr=array();foreach($this->to as $t){$toArr[]=$this->AddrFormat($t);}$to=implode(', ',$toArr);$params=sprintf("-oi -f %s",$this->Sender);if($this->Sender!=''&&strlen(ini_get('safe_mode'))<1){$old_from=ini_get('sendmail_from');ini_set('sendmail_from',$this->Sender);if($this->SingleTo===true&&count($toArr)>1){foreach($toArr as $key=>$val){$rt=@mail($val,$this->EncodeHeader($this->SecureHeader($this->Subject)),$body,$header,$params);$isSent=($rt==1)?1:0;$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);}}else{$rt=@mail($to,$this->EncodeHeader($this->SecureHeader($this->Subject)),$body,$header,$params);$isSent=($rt==1)?1:0;$this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);}}else{if($this->SingleTo===true&&count($toArr)>1){foreach($toArr as $key=>$val){$rt=@mail($val,$this->EncodeHeader($this->SecureHeader($this->Subject)),$body,$header,$params);$isSent=($rt==1)?1:0;$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);}}else{$rt=@mail($to,$this->EncodeHeader($this->SecureHeader($this->Subject)),$body,$header);$isSent=($rt==1)?1:0;$this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);}}if(isset($old_from)){ini_set('sendmail_from',$old_from);}if(!$rt){throw new phpmailerException($this->Lang('instantiate'),self::STOP_CRITICAL);}return true;}protected function SmtpSend($header,$body){$bad_rcpt=array();if(!$this->SmtpConnect()){throw new phpmailerException($this->Lang('smtp_connect_failed'),self::STOP_CRITICAL);}$smtp_from=($this->Send
PHP邮件一键发送支持HTML格式
5星 · 超过95%的资源 需积分: 48 35 浏览量
2017-11-07
15:35:11
上传
评论 1
收藏 12KB ZIP 举报
hujiafeng_
- 粉丝: 3
- 资源: 12
最新资源
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈