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

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

08 Feb 2025
PHPMailer:PHP郵件發(fā)送的利器 PHPMailer是廣受歡迎的開源PHP郵件發(fā)送庫,自2001年發(fā)布以來,一直是PHP開發(fā)者發(fā)送程序化郵件的首選方案之一,與Swiftmailer等其他流行庫并駕齊驅。本文將闡述為何PHPMailer優(yōu)于PHP內置的mail()函數,并提供代碼示例。 核心要點 PHPMailer是一個流行的開源PHP郵件發(fā)送庫,比PHP內置的mail()函數提供更多功能和靈活性,包括面向對象的接口、更輕松的HTML和附件處理,以及使用非本地郵件服務器的能力。 PHP

24 Nov 2017
相信很多同學都用過thinkphp,而thinkphp這個框架本身也有類庫,這篇文章我們來講講thinkphp怎么使用外部PHPMailer類庫。

25 Feb 2025
關鍵要點 Swift Mailer是一個功能強大的,基于組件的庫,允許程序員使用面向對象的方法輕松發(fā)送電子郵件,其要求最小為5.2或更高,具有SPL擴展名,最小內存限制為

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

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


熱工具

依賴注入容器的PHP庫
依賴注入容器的PHP庫

50個優(yōu)秀經典PHP算法大集合
經典PHP算法,學習優(yōu)秀的思想 , 開拓思維

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