smtp를 통해 이메일을 보내기 위한 파리 PHP 클래스의 smtown, 테스트 통과
smtp.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;
/* 생성자 */
함수 smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = 거짓;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //fsockopen()에서 사용됨
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost"; //HELO 명령에 사용됨
$this->log_file = "";
$this->sock = 거짓;
}
/* 주요 기능 */
기능 sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc ="", $bcc =" ", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(rn))(.)", "1.3", $body);
$header .= "MIME 버전:1.0rn";
if($mailtype=="HTML")
{
$header .= "Content-Type:text/htmlrn";
}
$header .= "받는 사람: ".$to."rn";
if ($cc != "")
{
$header .= "Cc: ".$cc."rn";
}
$header .= "보낸 사람: $from<".$from.">rn";
$header .= "제목: ".$subject."rn";
$header .= $additional_headers;
$header .= "날짜: ".date("r")."rn";
$header .= "X-Mailer:By Redhat(PHP/".phpversion().")rn";
list($msec, $sec) = explode(" ", microtime());
$header .= "메시지 ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">rn";
$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("오류: ".$rcpt_to."n으로 이메일을 보낼 수 없습니다.") ;
$sent = FALSE;
계속하세요.
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body))
{ $this->log_write( "이메일이 <".$rcpt_to.">n으로 전송되었습니다.");
}
else
{
$this->log_write("오류: <".$rcpt_to로 이메일을 보낼 수 없습니다.">n ");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("원격 호스트에서 연결이 끊어졌습니다.");
}
$sent를 반환;
}
/* 비공개 함수 */
함수 smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this- >smtp_putcmd("HELO", $helo))
{
return $this->smtp_error("HELO 명령 전송 중");
}
#auth
if($this->auth)
{
if (!$this->smtp_putcmd("AUTH LOGIN", base64_en 코드($this-> user)))
{
return $this->smtp_error("HELO 명령 전송 중");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass)))
{ this->smtp_error("HELO 명령을 보내는 중 ");
}
}
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">"))
{
return $this->smtp_error("sending MAIL FROM 명령');
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">"))
{
return $this-> smtp_error("RCPT TO 명령 보내기");
}
if (!$this->smtp_putcmd("DATA"))
{
return $this->smtp_error("DATA 명령 전송 중");
}
if (!$this->smtp_message($header, $body))
{
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom())
{
return $this->smtp_error("sending
}
if (!$this->smtp_putcmd("QUIT"))
{
return $this->smtp_error("QUIT 명령 보내기");
}
TRUE를 반환합니다.
}
함수 smtp_sockopen($address)
{
if ($this->relay_host == "")
{ ;smtp_sockopen_mx($주소 );
}
else
{
return $this->smtp_sockopen_relay();
}
}
함수 smtp_sockopen_relay()
{
$this->log_write("".$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("오류: 릴레이 호스트에 연결할 수 없습니다.".$this ->relay_host."n");
$this->log_write("오류: ".$errstr." (".$errno.")n");
FALSE를 반환합니다.
}
$this->log_write("릴레이 호스트에 연결되었습니다.".$this->relay_host."n");
TRUE를 반환합니다.
}
함수 smtp_sockopen_mx($address)
{
$domain = ereg_replace("^. @([^@] )$", "1", $address);
if (!@getmxrr($domain, $MXHOSTS))
{
$this->log_write("오류: MX를 해결할 수 없습니다."".$domain.""n");
FALSE를 반환합니다.
}
foreach ($MXHOSTS as $host)
{
$this->log_write("".$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("경고: mx 호스트에 연결할 수 없습니다.".$ 호스트 ."N");
$this->log_write("오류: ".$errstr." (".$errno.")n");
계속하세요.
}
$this->log_write("mx 호스트에 연결됨".$host."n");
TRUE를 반환합니다.
}
$this->log_write("오류: 모든 mx 호스트에 연결할 수 없습니다(".implode(", ", $MXHOSTS).")n");
FALSE를 반환합니다.
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."rn".$body);
$this->smtp_debug("> ".str_replace("rn", "n"."> ", $header."n> ".$body."n>"));
TRUE를 반환합니다.
}
함수 smtp_eom()
{
fputs($this->sock, "rn.rn");
$this->smtp_debug(". [EOM]n");
return $this->smtp_ok();
}
함수 smtp_ok()
{
$response = str_replace("rn", "", fgets($this->sock, 512));
$this->smtp_debug($response."n");
if (!ereg("^[23]", $response))
{
fputs($this->sock, "QUITrn");
fgets($this->sock, 512);
$this->log_write("오류: 원격 호스트가 반환됨"".$response.""n");
FALSE를 반환합니다.
}
TRUE를 반환합니다.
}
함수 smtp_putcmd($cmd, $arg = "")
{
if ($arg != "")
{
if($cmd=="")
{
$cmd = $arg;
}
else
{
$cmd = $cmd." ".$arg;
}
}
fputs($this->sock, $cmd."rn");
$this->smtp_debug("> ".$cmd."n");
return $this->smtp_ok();
}
함수 smtp_error($string)
{
$this->log_write("오류: 오류가 발생하는 동안".$string.".n");
FALSE를 반환합니다.
}
함수 log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "")
{
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("경고: 로그 파일을 열 수 없습니다."".$this->log_file.""n");
반환 FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
TRUE를 반환합니다.
}
function strip_comment($address)
{
$comment = "([^()]*)";
while (ereg($comment, $address))
{
$address = ereg_replace($comment, "", $address);
}
$address를 반환합니다.
}
function get_address($address)
{
$address = ereg_replace("([ trn]) ", "", $address);
$address = ereg_replace("^.*<(. )>.*$", "1", $address);
$address를 반환합니다.
}
함수 smtp_debug($message)
{
if ($this->debug)
{
echo $message;
}
}
}
?>
测试程序
复主代码 代码아래:
/*
테스트 프로그램입니다!!!
*/
require("smtp.php")
#### ################################
$smtpserver = "smtp.163.com "; //SMTP 서버
$smtpserverport = 25;//SMTP 서버 포트
$smtpusermail = "reterry123@163.com";//SMTP 서버 사용자 이메일
$smtpemailto = "dxytools@gmail .com" ;//보내는 사람
$smtpuser = "reterry123";//SMTP 서버의 사용자 계정
$smtppass = "014040001";//SMTP 서버의 사용자 비밀번호
$mailsubject = " Chinese" ;//이메일 제목
$mailbody = "
중국어
새해 분위기 조성 테스트";//이메일 내용$mailtype = "HTML";//이메일 형식( HTML/TXT), TXT는 텍스트 이메일
################################ ## ###
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//여기서 true는 인증이 사용됨을 의미하고, 그렇지 않으면 인증이 사용되지 않음을 의미합니다.
$smtp- >debug = TRUE;//전송된 디버그 정보를 표시할지 여부
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype)
?>
위 내용은 smtp in paris php를 통해 이메일을 보내는 클래스를 소개한 내용이며, smtown in paris 내용도 포함되어 있어 PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되었으면 좋겠습니다.

핫 AI 도구

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

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

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Alipay PHP ...

JWT는 주로 신분증 인증 및 정보 교환을 위해 당사자간에 정보를 안전하게 전송하는 데 사용되는 JSON을 기반으로 한 개방형 표준입니다. 1. JWT는 헤더, 페이로드 및 서명의 세 부분으로 구성됩니다. 2. JWT의 작업 원칙에는 세 가지 단계가 포함됩니다. JWT 생성, JWT 확인 및 Parsing Payload. 3. PHP에서 인증에 JWT를 사용하면 JWT를 생성하고 확인할 수 있으며 사용자 역할 및 권한 정보가 고급 사용에 포함될 수 있습니다. 4. 일반적인 오류에는 서명 검증 실패, 토큰 만료 및 대형 페이로드가 포함됩니다. 디버깅 기술에는 디버깅 도구 및 로깅 사용이 포함됩니다. 5. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

기사는 PHP 5.3에 도입 된 PHP의 LSB (Late STATIC BING)에 대해 논의하여 정적 방법의 런타임 해상도가보다 유연한 상속을 요구할 수있게한다. LSB의 실제 응용 프로그램 및 잠재적 성능

기사는 입력 유효성 검사, 인증 및 정기 업데이트를 포함한 취약점을 방지하기 위해 프레임 워크의 필수 보안 기능을 논의합니다.

PHP 개발에서 PHP의 CURL 라이브러리를 사용하여 JSON 데이터를 보내면 종종 외부 API와 상호 작용해야합니다. 일반적인 방법 중 하나는 컬 라이브러리를 사용하여 게시물을 보내는 것입니다 ...

PHP 개발에서 견고한 원칙의 적용에는 다음이 포함됩니다. 1. 단일 책임 원칙 (SRP) : 각 클래스는 하나의 기능 만 담당합니다. 2. Open and Close Principle (OCP) : 변경은 수정보다는 확장을 통해 달성됩니다. 3. Lisch의 대체 원칙 (LSP) : 서브 클래스는 프로그램 정확도에 영향을 미치지 않고 기본 클래스를 대체 할 수 있습니다. 4. 인터페이스 격리 원리 (ISP) : 의존성 및 사용되지 않은 방법을 피하기 위해 세밀한 인터페이스를 사용하십시오. 5. 의존성 반전 원리 (DIP) : 높고 낮은 수준의 모듈은 추상화에 의존하며 종속성 주입을 통해 구현됩니다.

이 기사에서는 프레임 워크에 사용자 정의 기능 추가, 아키텍처 이해, 확장 지점 식별 및 통합 및 디버깅을위한 모범 사례에 중점을 둡니다.

세션 납치는 다음 단계를 통해 달성 할 수 있습니다. 1. 세션 ID를 얻으십시오. 2. 세션 ID 사용, 3. 세션을 활성 상태로 유지하십시오. PHP에서 세션 납치를 방지하는 방법에는 다음이 포함됩니다. 1. 세션 _regenerate_id () 함수를 사용하여 세션 ID를 재생산합니다. 2. 데이터베이스를 통해 세션 데이터를 저장하십시오.
