<?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
相關文章
17 Jul 2017
本文以下面這個類別庫做為講解《強大的php發送郵件類別》點擊標題可以去下該類別庫。如果你需要查看更多的php類別庫可以點下面的連結:http://www.php.cn/xiazai/leiku
24 Nov 2017
我相信很多同學都用過thinkphp,而thinkphp這個框架本身也有類別庫,這篇文章我們來講講thinkphp怎麼使用外部PHPMailer類別庫。
15 Mar 2019
JavaMail API支援用於傳送電子郵件的JavaMail(javax.mail)介面。 javax.mail具有發送電子郵件和SMTP,POP3和IMAP等其他郵件協定所需的所有類別。
27 Dec 2023
了解Java開發中常用的郵件發送工具類別在現代社會中,電子郵件已成為人們溝通的重要方式之一。在Java開發中,我們通常需要使用郵件發送工具類別來實作郵件的傳送功能。本文將介紹一些常用的Java郵件發送工具類,並對其使用方法進行詳細的講解。首先,我們需要了解Java中的javax.mail套件。這個包提供了JavaEE平台中的郵件傳輸協定的實作。透過這個包,我們