首頁 PHP 函式庫 其它類別庫 發送電子郵件的php類
發送電子郵件的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

相關文章

PHP發送電子郵件類 PHP發送電子郵件類

25 Jul 2016

PHP發送電子郵件類

PHP發送電子郵件程式碼 PHP發送電子郵件程式碼

25 Jul 2016

PHP發送電子郵件程式碼

自動發送電子郵件 自動發送電子郵件

07 Nov 2024

?很高興分享我的專案—自動電子郵件發送系統? 我開發了一種工具,透過處理從客製化訊息到大規模分發的所有內容,可以更快、更有效率地發送電子郵件。 ?無論是用於行銷、提醒或

電子郵件發送服務 電子郵件發送服務

26 Jan 2025

NPM 和 GitHub 整合:使用 Node.js 簡化電子郵件發送 此 Node.js 應用程式使用 nodemailer 套件簡化了電子郵件發送。 以最少的配置享受無縫的電子郵件傳送。 主要特點: 輕量且高度客製化

如何解決 PHP Mail() 和 PHPMailer 的電子郵件傳送問題? 如何解決 PHP Mail() 和 PHPMailer 的電子郵件傳送問題?

22 Oct 2024

本文提供了使用 PHP mail() 或 PHPMailer 發送電子郵件時遇到的問題的偵錯解決方案。它解決了與 mail() 函數和缺少 PHPMailer 類別導入相關的錯誤。文章建議啟用 SMTP debuggin

發送郵件的PHP類 發送郵件的PHP類

25 Jul 2016

發送郵件的PHP類

See all articles