찾다
백엔드 개발PHP 튜토리얼 PHP发送信箱激活验证

PHP发送邮箱激活验证

第一步:php连接数据库:dbconnection.php

 

$server = "(local)";
$_uid = "adweb";
$_pwd = "loveyou";
$_database = "addev";


 function sqlsrv_connect( $server , $uid ,$pwd,$db  ){
    
    $connect_id= mssql_connect($server, $uid, $pwd);
           //echo $connect_id ;
   if($connect_id){
               if (mssql_select_db($db,$connect_id))
                   return $connect_id ;
    else
     echo mssql_get_last_message() ; 
           }
   else
    echo mssql_get_last_message() ;
 }

 function sqlsrv_query($SQL,$conn  ) {
   returnmssql_query( $SQL ,$conn ) ;
 }

function sqlsrv_num_rows($n) {
 
 return mssql_num_rows($n) ;

}
function sqlsrv_fetch_array($n) {

  returnmssql_fetch_array($n);
}
//调用函数,连接数据库
$conn = sqlsrv_connect( $server , $_uid ,$_pwd,$_database  ) ;

?>

 

第二步:邮箱类email.class.php

 


class smtp
{

var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;


var $sock;


function smtp($relay_host = "", $smtp_port = 25,$auth =false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
#
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
#
$this->host_name = "localhost"; //is used in HELOcommand
$this->log_file ="";

$this->sock = FALSE;
}


function sendmail($to, $from, $subject = "", $body = "", $mailtype,$cc = "", $bcc = "", $additional_headers = "")
{
$mail_from =$this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\\.)", "\\1.\\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From:$from\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: \r\n";
$TO = explode(",", $this->strip_comment($to));

if ($cc != "") {
$TO = array_merge($TO, explode(",",$this->strip_comment($cc)));
}

if ($bcc != "") {
$TO = array_merge($TO, explode(",",$this->strip_comment($bcc)));
}

$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("Error: Cannot send email to".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if($this->smtp_send($this->host_name,$mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E-mail has been sent to\n");
} else {
$this->log_write("Error: Cannot send email to\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remotehost\n");
}
echo "
";
echo $header;
return $sent;
}

function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo)) {
return $this->smtp_error("sending HELOcommand");
}
#auth
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN",base64_encode($this->user))) {
return $this->smtp_error("sending HELOcommand");
}

if (!$this->smtp_putcmd("",base64_encode($this->pass))) {
return $this->smtp_error("sending HELOcommand");
}
}
#
if (!$this->smtp_putcmd("MAIL","FROM:")) {
return $this->smtp_error("sending MAIL FROMcommand");
}

if (!$this->smtp_putcmd("RCPT","TO:")) {
return $this->smtp_error("sending RCPT TOcommand");
}

if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATAcommand");
}

if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("sending message");
}

if (!$this->smtp_eom()) {
return $this->smtp_error("sending.[EOM]");
}

if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("sending QUITcommand");
}

return TRUE;
}

function smtp_sockopen($address)
{
if ($this->relay_host == "") {
return $this->smtp_sockopen_mx($address);
} else {
return $this->smtp_sockopen_relay();
}
}

function smtp_sockopen_relay()
{
$this->log_write("Trying to".$this->relay_host.":".$this->smtp_port."\n");
$this->sock =@fsockopen($this->relay_host,$this->smtp_port, $errno, $errstr,$this->time_out);
if (!($this->sock &&$this->smtp_ok())) {
$this->log_write("Error: Cannot connenct to relayhost ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr."(".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host".$this->relay_host."\n");
return TRUE;;
}

function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\\1", $address);
if (!@getmxrr($domain,$MXHOSTS)) {
$this->log_write("Error: Cannot resolve MX\"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this->log_write("Trying to".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host,$this->smtp_port, $errno, $errstr,$this->time_out);
if (!($this->sock &&$this->smtp_ok())) {
$this->log_write("Warning: Cannot connect to mx host".$host."\n");
$this->log_write("Error: ".$errstr."(".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mxhosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}

function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug(">".str_replace("\r\n", "\n"."> ",$header."\n> ".$body."\n> "));

return TRUE;
}

function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");

return $this->smtp_ok();
}

function smtp_ok()
{
$response = str_replace("\r\n", "",fgets($this->sock, 512));
$this->smtp_debug($response."\n");

if (!ereg("^[23]", $response)) {
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned\"".$response."\"\n");
return FALSE;
}
return TRUE;
}

function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}

fputs($this->sock, $cmd."\r\n");
$this->smtp_debug(">".$cmd."\n");

return $this->smtp_ok();
}

function smtp_error($string)
{
$this->log_write("Error: Error occurred while".$string.".\n");
return FALSE;
}

function log_write($message)
{
$this->smtp_debug($message);

if ($this->log_file == "") {
return TRUE;
}

$message = date("M d H:i:s").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file)|| !($fp = @fopen($this->log_file, "a"))) {
$this->smtp_debug("Warning: Cannot open log file\"".$this->log_file."\"\n");
return FALSE;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);

return TRUE;
}

function strip_comment($address)
{
$comment = "\\([^()]*\\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}

return $address;
}

function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address =ereg_replace("^.*.*$","\\1", $address);

return $address;
}

function smtp_debug($message)
{
if ($this->debug) {
echo $message."
";
}
}

function get_attach_type($image_tag) { //

$filedata = array();

$img_file_con=fopen($image_tag,"r");
unset($image_data);
while($tem_buffer=AddSlashes(fread($img_file_con,filesize($image_tag))))
$image_data.=$tem_buffer;
fclose($img_file_con);

$filedata['context'] = $image_data;
$filedata['filename']= basename($image_tag);
$extension=substr($image_tag,strrpos($image_tag,"."),strlen($image_tag)-strrpos($image_tag,"."));
switch($extension){
case ".gif":
$filedata['type'] = "image/gif";
break;
case ".gz":
$filedata['type'] = "application/x-gzip";
break;
case ".htm":
$filedata['type'] = "text/html";
break;
case ".html":
$filedata['type'] = "text/html";
break;
case ".jpg":
$filedata['type'] = "image/jpeg";
break;
case ".tar":
$filedata['type'] = "application/x-tar";
break;
case ".txt":
$filedata['type'] = "text/plain";
break;
case ".zip":
$filedata['type'] = "application/zip";
break;
default:
$filedata['type'] = "application/octet-stream";
break;
}


return $filedata;
}

}
?>

第三步:激活类jihuo.php

require('dbconnection.php');

  echo $_GET['code'];
  echo "已经激活";
  echo "


";
if($_GET[code]) {
 $result=sqlsrv_query(  'select *from actcode  where code="'.$_GET[code].'"',$conn);   //查询数据库中是否有此激活账号
 if(sqlsrv_num_rows($result) == 1 ) {
    //$_ROW =sqlsrv_fetch_array( $result );
  //$i = sqlsrv_query( 'updateADUser  set status=5 whereemail="'.$_ROW[email].'"', $conn ); //修改注册时此邮箱用户的状态值为1
  //if($i){
   //sqlsrv_query( ' delete  from actcode wherecode="'.$_GET[code].'"' ,$conn );
   echo'邮箱激活-请到主页登陆' ;
   //} 
 }
 else{
  echo '验证已结束' ;
 }

}
?>

 

第四步:发送邮箱类sendemail.php

 //发送激活邮件
require_once ('email.class.php');
require('dbconnection.php');

//##########################################
$smtpserver = "smtp.163.com";//SMTP服务器163/126/sohu/qq/xinlang
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = "zxwzxw_1@163.com";//SMTP服务器的用户邮箱
$smtpuser = "zxwzxw_1";//SMTP服务器的用户帐号
$smtppass = "doyoumissme";//SMTP服务器的用户密码
$mailsubject = "你好,很高兴认识你!";//邮件主题
$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
##########################################
$smtp = newsmtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp->debug = false;//是否显示发送的调试信息
$toemail = "zxwzxw_12@163.com"; //收件人邮箱
$actcodes =md5($toemail.mt_rand(111111,999999)); 
$mmsg = '您已经注册成功 ,请将点击以下链接激活您的账号: 点击激活';

 $hh = sqlsrv_query('insert intoactcode(code,email) values("'.$actcodes.'" , "'.$toemail.'")',$conn);  //把注册时的邮箱号和验证插入数据表中
if($hh){
   $smtp->sendmail($toemail, $smtpusermail,$mailsubject, $mmsg,$mailtype);   //发送邮件
}
else {
 echo '发送失败!';
 exit;
}
   

?>

 

第五步:最后 :  发送邮箱激活验证.txt

 

1 建立数据库:addev  表ACTcode  字段code varchar(50)   emailvarchar(50)

2 连接数据:dbconnection.php

$server = "(local)";
$_uid = "adweb";
$_pwd = "loveyou";
$_database = "addev";


 function sqlsrv_connect( $server , $uid ,$pwd,$db  ){
    
    $connect_id= mssql_connect($server, $uid, $pwd);
           //echo $connect_id ;
   if($connect_id){
               if (mssql_select_db($db,$connect_id))
                   return $connect_id ;
    else
     echo mssql_get_last_message() ; 
           }
   else
    echo mssql_get_last_message() ;
 }


//调用函数,连接数据库
$conn = sqlsrv_connect( $server , $_uid ,$_pwd,$_database  ) ;

?>


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

PHP와 Python은 각각 고유 한 장점이 있으며 선택은 프로젝트 요구 사항을 기반으로해야합니다. 1.PHP는 간단한 구문과 높은 실행 효율로 웹 개발에 적합합니다. 2. Python은 간결한 구문 및 풍부한 라이브러리를 갖춘 데이터 과학 및 기계 학습에 적합합니다.

PHP : 죽어 가거나 단순히 적응하고 있습니까?PHP : 죽어 가거나 단순히 적응하고 있습니까?Apr 11, 2025 am 12:13 AM

PHP는 죽지 않고 끊임없이 적응하고 진화합니다. 1) PHP는 1994 년부터 새로운 기술 트렌드에 적응하기 위해 여러 버전 반복을 겪었습니다. 2) 현재 전자 상거래, 컨텐츠 관리 시스템 및 기타 분야에서 널리 사용됩니다. 3) PHP8은 성능과 현대화를 개선하기 위해 JIT 컴파일러 및 기타 기능을 소개합니다. 4) Opcache를 사용하고 PSR-12 표준을 따라 성능 및 코드 품질을 최적화하십시오.

PHP의 미래 : 적응 및 혁신PHP의 미래 : 적응 및 혁신Apr 11, 2025 am 12:01 AM

PHP의 미래는 새로운 기술 트렌드에 적응하고 혁신적인 기능을 도입함으로써 달성 될 것입니다. 1) 클라우드 컴퓨팅, 컨테이너화 및 마이크로 서비스 아키텍처에 적응, Docker 및 Kubernetes 지원; 2) 성능 및 데이터 처리 효율을 향상시키기 위해 JIT 컴파일러 및 열거 유형을 도입합니다. 3) 지속적으로 성능을 최적화하고 모범 사례를 홍보합니다.

PHP의 초록 클래스 또는 인터페이스에 대한 특성과 언제 특성을 사용 하시겠습니까?PHP의 초록 클래스 또는 인터페이스에 대한 특성과 언제 특성을 사용 하시겠습니까?Apr 10, 2025 am 09:39 AM

PHP에서, 특성은 방법 재사용이 필요하지만 상속에 적합하지 않은 상황에 적합합니다. 1) 특성은 클래스에서 다중 상속의 복잡성을 피할 수 있도록 수많은 방법을 허용합니다. 2) 특성을 사용할 때는 대안과 키워드를 통해 해결할 수있는 방법 충돌에주의를 기울여야합니다. 3) 성능을 최적화하고 코드 유지 보수성을 향상시키기 위해 특성을 과도하게 사용해야하며 단일 책임을 유지해야합니다.

DIC (Dependency Injection Container) 란 무엇이며 PHP에서 사용하는 이유는 무엇입니까?DIC (Dependency Injection Container) 란 무엇이며 PHP에서 사용하는 이유는 무엇입니까?Apr 10, 2025 am 09:38 AM

의존성 주입 컨테이너 (DIC)는 PHP 프로젝트에 사용하기위한 객체 종속성을 관리하고 제공하는 도구입니다. DIC의 주요 이점에는 다음이 포함됩니다. 1. 디커플링, 구성 요소 독립적 인 코드는 유지 관리 및 테스트가 쉽습니다. 2. 유연성, 의존성을 교체 또는 수정하기 쉽습니다. 3. 테스트 가능성, 단위 테스트를 위해 모의 객체를 주입하기에 편리합니다.

SPL SplfixedArray 및 일반 PHP 어레이에 비해 성능 특성을 설명하십시오.SPL SplfixedArray 및 일반 PHP 어레이에 비해 성능 특성을 설명하십시오.Apr 10, 2025 am 09:37 AM

SplfixedArray는 PHP의 고정 크기 배열로, 고성능 및 메모리 사용이 필요한 시나리오에 적합합니다. 1) 동적 조정으로 인한 오버 헤드를 피하기 위해 생성 할 때 크기를 지정해야합니다. 2) C 언어 배열을 기반으로 메모리 및 빠른 액세스 속도를 직접 작동합니다. 3) 대규모 데이터 처리 및 메모리에 민감한 환경에 적합하지만 크기가 고정되어 있으므로주의해서 사용해야합니다.

PHP는 파일 업로드를 어떻게 단단히 처리합니까?PHP는 파일 업로드를 어떻게 단단히 처리합니까?Apr 10, 2025 am 09:37 AM

PHP는 $ \ _ 파일 변수를 통해 파일 업로드를 처리합니다. 보안을 보장하는 방법에는 다음이 포함됩니다. 1. 오류 확인 확인, 2. 파일 유형 및 크기 확인, 3 파일 덮어 쓰기 방지, 4. 파일을 영구 저장소 위치로 이동하십시오.

Null Coalescing 연산자 (??) 및 Null Coalescing 할당 연산자 (?? =)은 무엇입니까?Null Coalescing 연산자 (??) 및 Null Coalescing 할당 연산자 (?? =)은 무엇입니까?Apr 10, 2025 am 09:33 AM

JavaScript에서는 NullCoalescingOperator (??) 및 NullCoalescingAssignmentOperator (?? =)를 사용할 수 있습니다. 1. 2. ??= 변수를 오른쪽 피연산자의 값에 할당하지만 변수가 무효 또는 정의되지 않은 경우에만. 이 연산자는 코드 로직을 단순화하고 가독성과 성능을 향상시킵니다.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

Dreamweaver Mac版

Dreamweaver Mac版

시각적 웹 개발 도구

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경