이메일 전송을 위한 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
관련 기사
25 Jul 2016
웹페이지 하이퍼링크, 이메일 주소 및 기타 콘텐츠를 추출하기 위한 PHP 구현 코드
![PHP의 mail() 기능은 대량 이메일 전송을 위한 신뢰할 수 있는 선택입니까?](https://img.php.cn/upload/article/001/246/273/173124522447752.jpg)
10 Nov 2024
PHP의 대량 이메일 전달: 장점과 단점 효율적인 대량 이메일 전달을 위해서는 제한 사항과 함정을 고려하는 것이 중요합니다.
![](/static/imghw/down_right.png)
![](/static/imghw/taglogo.png)
Hot Tools
![종속성 주입 컨테이너용 PHP 라이브러리](https://img.php.cn/upload/manual/000/000/001/5e2171bf3c005481.png)
종속성 주입 컨테이너용 PHP 라이브러리
종속성 주입 컨테이너용 PHP 라이브러리
50개의 뛰어난 클래식 PHP 알고리즘 모음
클래식 PHP 알고리즘, 훌륭한 아이디어를 배우고 사고력을 확장하세요
이미지 최적화를 위한 작은 PHP 라이브러리
이미지 최적화를 위한 작은 PHP 라이브러리
![](/static/imghw/taglogo.png)
인기 기사
Tales Of Graces F Remastered: 모든 잠긴 상자 비밀번호
18 Jan 2025
모바일 게임 가이드
붕괴: 스타레일 - 모든 황금 희생양 퍼즐 솔루션
18 Jan 2025
모바일 게임 가이드
왕국 Come : 구원 2- 결혼식을 위해 사야 할 옷
05 Feb 2025
모바일 게임 가이드
진흥 전사: 기원 - 모든 엔딩을 보는 방법
16 Jan 2025
모바일 게임 가이드
왕국 Come : 구원 2- Comfrey를 얻는 방법
07 Feb 2025
모바일 게임 가이드