이메일 전송을 위한 PHP 클래스
<?php class SendM{ private $Mailhost,$Mailuser,$Mailpwd,$Mailport,$Mailtimeout,$ms,$ending = "\r\n",$endingc="\n"; function __construct($Mailhost,$Mailuser,$Mailpwd,$Mailport,$Mailtimeout){ $this->Mailhost=$Mailhost; $this->Mailuser=$Mailuser; $this->Mailpwd=$Mailpwd; $this->Mailport=$Mailport; $this->Mailtimeout=$Mailtimeout; $this->ConnectSmtpServer(); } private function ConnectSmtpServer(){ if(!is_string($this->Mailhost)){ settype(trim($this->Mailhost),"string"); } if(!is_integer($this->Mailport)){ settype(trim($this->Mailport),"integer"); } if(!is_integer($this->Mailtimeout)){ settype(trim($this->Mailtimeout),"integer"); } $this->ms=@fsockopen($this->Mailhost,$this->Mailport,$this->errorno,$this->errorstr,$this->Mailtimeout); if(substr(PHP_OS,0,3) != "WIN"){ stream_set_timeout($this->ms, $this->Mailtimeout, 0);} $rcp = $this->get_echo(); fputs($this->ms,"ehlo bobo".$this->ending); $rcp = $this->get_echo(); if(substr($rcp,0,3)!='250'){ return false; } fputs($this->ms,'auth login'.$this->ending); $rcp = $this->get_echo(); if(substr($rcp,0,3)=='334'){ $this->Auth($this->Mailuser,$this->Mailpwd); }else{ return false; } } private function Auth($Mailuser,$Mailpwd){ $this->Mailuseren=base64_encode($Mailuser); $this->Mailpwden=base64_encode($Mailpwd); fputs($this->ms,$this->Mailuseren.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,$this->Mailpwden.$this->ending); $rcp = $this->get_echo(); } private function get_echo(){ $edata=""; while($estr=@fgets($this->ms,600)){ $edata .= $estr; if(substr($estr,3,1) == " ") { break; } } return $edata; } public function Send($to,$subject,$connect){ $host=explode('.',$this->Mailhost); $fromaddress=$this->Mailuser.'@'.$host[1].'.'.$host[2]; fputs($this->ms,'mail from:<'.$fromaddress.'>'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,'rcpt to:<'.$to.'>'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,'data'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,"to:$to".$this->endingc); fputs($this->ms,"from:$fromaddress".$this->endingc); fputs($this->ms,"subject:$subject".$this->endingc.$this->endingc); fputs($this->ms,"$connect".$this->endingc); fputs($this->ms,'.'.$this->ending); $rcp = $this->get_echo(); if(substr($rcp,0,3)=='250'){header("Location:main_pro.php?act=msg&errors=on&msg=邮件发送成功!已成功提交至对方服务器!"); }else{ header("Location:main_pro.php?act=msg&errors=on&msg=很遗憾,邮件发送失败了!请检查邮件账户配置是否正确!"); } } } ?>
이메일 보내기를 위한 PHP 클래스입니다. 필요한 친구들은 다운로드해서 사용할 수 있습니다.
사용 지침:
$m= new SendM('smtp 서버 주소', '계정', '비밀번호', 포트(int), 시간 초과 재시도 시간(int))
$m->Send( '받는 사람의 이메일','제목','이메일 내용');
사용 예:
$m= new SendM('smtp.yeah.net','testuser','testuserpwd',25,30 );
$m->Send('a@coolmr.com','테스트 이메일','이메일 발송을 위한 테스트 이메일입니다. 지원해 주셔서 감사합니다.');
부인 성명
이 사이트의 모든 리소스는 네티즌이 제공하거나 주요 다운로드 사이트에서 재인쇄되었습니다. 소프트웨어의 무결성을 직접 확인하십시오! 이 사이트의 모든 리소스는 학습 참고용으로만 사용됩니다. 상업적 목적으로 사용하지 마시기 바랍니다. 그렇지 않으면 모든 결과에 대한 책임은 귀하에게 있습니다! 침해가 있는 경우 당사에 연락하여 삭제하시기 바랍니다. 연락처: admin@php.cn
관련 기사

25Jul2016
웹페이지 하이퍼링크, 이메일 주소 및 기타 콘텐츠를 추출하기 위한 PHP 구현 코드

10Nov2024
PHP의 대량 이메일 전달: 장점과 단점 효율적인 대량 이메일 전달을 위해서는 제한 사항과 함정을 고려하는 것이 중요합니다.


Hot Tools

종속성 주입 컨테이너용 PHP 라이브러리
종속성 주입 컨테이너용 PHP 라이브러리

50개의 뛰어난 클래식 PHP 알고리즘 모음
클래식 PHP 알고리즘, 훌륭한 아이디어를 배우고 사고력을 확장하세요

이미지 최적화를 위한 작은 PHP 라이브러리
이미지 최적화를 위한 작은 PHP 라이브러리

인기 기사
잃어버린 기록 : Bloom & Rage -Corey 및 Dylan 's Lock Combine
19Feb2025모바일 게임 가이드
헬로키티 아일랜드 어드벤처: 초코캣 캐릭터 가이드
24Jan2025모바일 게임 가이드
KB5050081을 수정하는 방법 Windows 10에 설치되지 않습니까?
31Jan2025문제 해결
chatgpt를 사용하지 않더라도 AI Checkers가 글을 표시 할 수있는 4 가지 이유
27Jan2025일체 포함
왕조 전사 : 기원 - 신나이 연습의 전투
26Jan2025모바일 게임 가이드