>  기사  >  php教程  >  自己写的一个php发送邮件的类(smtp协议)

自己写的一个php发送邮件的类(smtp协议)

PHP中文网
PHP中文网원래의
2016-05-25 17:07:093491검색

              

 Smtp = $Smtp; return $this; }
	public function pors( $pors = 25 ){ $this -> PORS = $pors; return $this; }
	public function login( $login = '' ) { $this -> LoginMail = $login; return $this; }
	public function pass( $pass = '' ){ $this -> LoginPass = $pass; return $this; }
	public function mails( $mail = '' ) { $this -> MailTo = $mail; return $this; }
	public function from( $form = '' ) { $this -> MailFrom = $form; return $this; }
	public function come( $come = '' ) { $this -> MailCome = $come; return $this; }
	public function title( $title = '' ) { $this -> Title = $title; return $this; }
	public function body( $body = '' ) { $this -> Body = $body; return $this; }
	
	
	public function send(){
		  $fp     = @fsockopen( $this->Smtp, $this->PORS);
		  @set_socket_blocking($fp, true);
		  $Server =  @fgets($fp, 512);
		  $this->Mesg = !preg_match('/^220/i', $Server) ? '邮件服务器连接失败' : $this->Mesg;
		  
		  @fputs($fp, 'HELO phpsetmail' . "\r\n");
		  $Server = @fgets($fp, 2000);
		  $this->Mesg = !preg_match('/^250/i', $Server) ? '与服务器会话失败' : $this->Mesg;
		  
		  @fputs($fp, 'AUTH LOGIN' . "\r\n");
		  $Server = @fgets($fp, 2000);
		  $this->Mesg = !preg_match('/^334/i', $Server) ? '请求与服务器进行用户验证失败' : $this->Mesg;
		  
		  @fputs($fp, base64_encode( $this->LoginMail ) . "\r\n");
		  $Server = @fgets($fp, 2000);
		  $this->Mesg = !preg_match('/^334/i', $Server) ? '用户验证失败' : $this->Mesg;
		  
		  @fputs($fp, base64_encode( $this->LoginPass ) . "\r\n");
		  $Server = @fgets($fp, 2000);
		  $this->Mesg = !preg_match('/^235/i', $Server) ? '用户验证失败' : $this->Mesg;
		  
		  @fputs($fp, 'MAIL FROM:' . $this->LoginMail . "\r\n");
		  $Server = @fgets($fp, 2000);
		  $this->Mesg = !preg_match('/^250/i', $Server) ? '发送用户验证失败' : $this->Mesg;
		  
		  @fputs($fp, 'RCPT TO:' . $this->MailTo . "\r\n");
		  $Server = @fgets($fp, 2000);
		  $this->Mesg = !preg_match('/^250/i', $Server) ? '接受用户名验证失败' : $this->Mesg;
		  
		  @fputs($fp, 'DATA' . "\r\n");
		  $Server = @fgets($fp, 2000);
		  $this->Mesg = !preg_match('/^354/i', $Server) ? '请求与服务器发送邮件数据失败' : $this->Mesg;
		  
		  @fputs($fp, 'From:' . $this->MailCome ."\r\n");
		  @fputs($fp, 'Subject:' . $this->Title . "\r\n");
		  @fputs($fp, 'To:' . $this->MailTo . "\r\n");
		  @fputs($fp, "\r\n");
		  @fputs($fp, $this->Body . "\r\n");
		  @fputs($fp, '.' . "\r\n");
		  
		  $Server = @fgets($fp, 2000);
		  $this->Mesg = !preg_match('/^250/i', $Server) ? '邮件发送失败' : $this->Mesg;
		  
		  @@fputs($fp, 'QUIT' . "\r\n");
		  @fclose($fp);
		 return $this->Mesg;
	}
	
}

                                   

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.