<?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=郵件發(fā)送成功!已成功提交至對(duì)方服務(wù)器!"); }else{ header("Location:main_pro.php?act=msg&errors=on&msg=很遺憾,郵件發(fā)送失敗了!請(qǐng)檢查郵件賬戶配置是否正確!"); } } } ?>
這是一個(gè)發(fā)送電子郵件的php類,需要的朋友可以下載使用。
使用說(shuō)明:
$m= new SendM('smtp服務(wù)器地址','賬號(hào)','密碼',端口(int),超時(shí)重試時(shí)間(int));
$m->Send('收件人郵箱 ','主題','郵件正文內(nèi)容');
使用范例:
$m= new SendM('smtp.yeah.net','testuser','testuserpwd',25,30);
$m->Send('a@coolmr.com ','測(cè)試郵件','這是一封郵件發(fā)送類的測(cè)試郵件,謝謝您的支持');
本站所有資源均由網(wǎng)友貢獻(xiàn)或各大下載網(wǎng)站轉(zhuǎn)載。請(qǐng)自行檢查軟件的完整性!本站所有資源僅供學(xué)習(xí)參考。請(qǐng)不要將它們用于商業(yè)目的。否則,一切后果由您負(fù)責(zé)!如有侵權(quán),請(qǐng)聯(lián)系我們刪除。聯(lián)系方式:admin@php.cn
相關(guān)文章

02 Mar 2025
核心要點(diǎn) PHP 提供了一種簡(jiǎn)單有效的方法來(lái)發(fā)送電子郵件,包括基本的純文本郵件、HTML 郵件和帶有附件的郵件。 PHP 的 mail() 函數(shù)用于發(fā)送電子郵件。對(duì)于簡(jiǎn)單的郵件,它只需要三個(gè)參數(shù):收件人的地址、主題和郵件正文。 發(fā)送 HTML 郵件或帶有附件的郵件時(shí),需要使用 MIME 標(biāo)準(zhǔn)將郵件分解成多個(gè)部分,并用選定的邊界分隔。每個(gè)部分都應(yīng)定義內(nèi)容是什么、如何編碼、可能的內(nèi)容處置方式,以及內(nèi)容本身。 使用 PHPMailer 庫(kù)可以增強(qiáng) PHP 發(fā)送郵件的功能,該庫(kù)允許連接 SMTP 服務(wù)

08 Feb 2025
PHPMailer:PHP郵件發(fā)送的利器 PHPMailer是廣受歡迎的開源PHP郵件發(fā)送庫(kù),自2001年發(fā)布以來(lái),一直是PHP開發(fā)者發(fā)送程序化郵件的首選方案之一,與Swiftmailer等其他流行庫(kù)并駕齊驅(qū)。本文將闡述為何PHPMailer優(yōu)于PHP內(nèi)置的mail()函數(shù),并提供代碼示例。 核心要點(diǎn) PHPMailer是一個(gè)流行的開源PHP郵件發(fā)送庫(kù),比PHP內(nèi)置的mail()函數(shù)提供更多功能和靈活性,包括面向?qū)ο蟮慕涌凇⒏p松的HTML和附件處理,以及使用非本地郵件服務(wù)器的能力。 PHP

24 Nov 2017
相信很多同學(xué)都用過(guò)thinkphp,而thinkphp這個(gè)框架本身也有類庫(kù),這篇文章我們來(lái)講講thinkphp怎么使用外部PHPMailer類庫(kù)。

25 Feb 2025
關(guān)鍵要點(diǎn) Swift Mailer是一個(gè)功能強(qiáng)大的,基于組件的庫(kù),允許程序員使用面向?qū)ο蟮姆椒ㄝp松發(fā)送電子郵件,其要求最小為5.2或更高,具有SPL擴(kuò)展名,最小內(nèi)存限制為

19 May 2025
sendingemailswithphpisstraightforwardusingthemail()functionormoreadvancedLibrariesLikeLikePhpMailer.1)usemail()forbasicemails,settrecipients,settrecipients,subjects,message,messages,andheaders.2)forhtmlemails,juspeStheadeStheadeSteStheadeSteStospeSpepeSpepeSpepeSpepeCifyHtmlConteN.3)

13 May 2025
phpemailvalidation invoLvesthreesteps:1)格式化進(jìn)行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)


熱門工具標(biāo)簽

熱工具

依賴注入容器的PHP庫(kù)
依賴注入容器的PHP庫(kù)

50個(gè)優(yōu)秀經(jīng)典PHP算法大集合
經(jīng)典PHP算法,學(xué)習(xí)優(yōu)秀的思想 , 開拓思維

小巧的優(yōu)化圖片的PHP庫(kù)
小巧的優(yōu)化圖片的PHP庫(kù)
