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 = 거짓;
}
/* 주요 기능 */
function 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) = 폭발(" ", 마이크로타임());
$header .= "메시지 ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">;rn" ;
$TO = 폭발(",", $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를 $rcpt_to로) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("오류: ".$rcpt_to."n으로 이메일을 보낼 수 없습니다");
$sent = 거짓;
계속;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E- 메일이 <".$rcpt_to.">n")으로 전송되었습니다.
} else {
$this->log_write("오류: <".$rcpt_to.">;n으로 이메일을 보낼 수 없습니다");
$sent = 거짓;
}
fclose($this->sock);
$this->log_write("원격 호스트에서 연결이 끊어졌습니다.");
}
$보낸 것을 반환합니다.
}
/* 비공개 함수 */
function 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_encode($this->user)) ) {
return $this->smtp_error("HELO 명령을 보내는 중");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
return $this->smtp_error("HELO 명령 전송 중");
}
}
#
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">;")) {
return $this->smtp_error("MAIL FROM 명령을 보내는 중");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">;")) {
return $this->smtp_error( "RCPT TO 명령을 보내는 중");
}
if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATA 명령");
}
if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("메시지를 보내는 중");
}
if (!$this->smtp_eom()) {
return $this->smtp_error("sending
}
if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("QUIT 명령 보내기");
}
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("".$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를 $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 호스트 ".$host."n에 연결할 수 없습니다."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를 반환합니다.
}
function smtp_eom()
{
fputs($this->sock, "rn.rn");
$this->smtp_debug(". [EOM]n");
return $this->smtp_ok();
}
function 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;
그렇지 않으면 $cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."rn");
$this->smtp_debug(">; ".$cmd."n");
return $this->smtp_ok();
}
function 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를 반환합니다.
}
군집($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
TRUE를 반환합니다.
}
function Strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
$address를 반환합니다.
}
함수 get_address($address)
{
$address = ereg_replace("([ trn])+", "", $address);
$address = ereg_replace("^.*<(.+)>;.*$", "\1", $address);
$address를 반환합니다.
}
함수 smtp_debug($message)
{
if ($this->debug) {
echo $message;
}
}
}
기능 sendmail($smtpserver,$smtpuser,$smtppass,$smtpemailto,$smtpusermail, $mailsubject, $mailbody){
$smtp = 새 smtp($ smtpserver,25,true,$smtpuser,$smtppass);
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, "HTML");
}
//sendmail("smtp.126.com","test@126.com","password","1034555083@qq.com","test@126.com", "제목","본문");
//$smtpserver = "SMTP.163.com"; //smtp服务器的地址
$smtpserver="smtp.qq.com";
$port =25; //smtp服务器的端口,一般是 25
$smtpuser = "116206443@emil.com"; //smtp服务器의 사용자 이름
$smtppwd = "123456789oiuy"; //您登录smtp服务器的密码
$mailtype = "TXT"; //가장 좋은 유형, 可选值是 TXT 或 HTML ,TXT 表示是纯文本的邮件,HTML 表示是 html格式的邮件
$sender = "116206443@qq.com";
//发件人, 一般要与您登录smtp服务器의 사용자 이름($smtpuser)상동,否则可能会因为smtp服务器的设置导致发送失败
$smtp = 새 smtp($smtpserver,$port ,true,$smtpuser,$smtppwd,$sender);
$smtp->디버그 = true; //是否开启调试,只在测试程序时使用, 正式使用时请将此行注释
$to = "116206443@qq.com"; //收件人
$subject = "你好";
$body = "测试发送的内容";
$send=$smtp->sendmail($to,$sender,$subject,$body,$mailtype);
if($send==1){
echo "邮件发送成功";
}else{
echo "邮件发送失败
";
//echo "원래:".$this->smtp->logs;
}
?>

핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++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. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

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

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

시스템이 다시 시작된 후 UnixSocket의 권한을 자동으로 설정하는 방법. 시스템이 다시 시작될 때마다 UnixSocket의 권한을 수정하려면 다음 명령을 실행해야합니다.

phpstorm에서 CLI 모드를 디버그하는 방법은 무엇입니까? PHPStorm으로 개발할 때 때때로 CLI (Command Line Interface) 모드에서 PHP를 디버그해야합니다 ...

정적 바인딩 (정적 : :)는 PHP에서 늦은 정적 바인딩 (LSB)을 구현하여 클래스를 정의하는 대신 정적 컨텍스트에서 호출 클래스를 참조 할 수 있습니다. 1) 구문 분석 프로세스는 런타임에 수행됩니다. 2) 상속 관계에서 통화 클래스를 찾아보십시오. 3) 성능 오버 헤드를 가져올 수 있습니다.

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