當前位置:首頁 » 雲伺服器 » php搭建郵件伺服器

php搭建郵件伺服器

發布時間: 2022-09-09 15:48:33

㈠ 新手想做一個php的表單提交發送到指定郵箱,請高手指教

首先包含一個郵件發送類 require("sendMail.php");
然後你要有一個發送郵件的伺服器(可以到163隨意注冊個,例如注冊的是[email protected],密碼是aa123),然後是發送郵件的代碼,我給你一個我用的例子
$smtpserver = "smtp.163.com"; //你選擇的SMTP伺服器
$smtpserverport =25; //SMTP伺服器埠
$smtpusermail = "[email protected]"; //SMTP伺服器的用戶郵箱
$smtpemailto = "[email protected]"; //收件箱
$smtpuser = "[email protected]"; //SMTP伺服器的用戶帳號
$smtppass = "aa123"; //SMTP伺服器的用戶密碼
$MailBody="姓名:".$_POST['Name'];//郵件內容(如你提交的表單姓名為Name)
$mailsubject=@iconv("UTF-8", "gb2312", "XX網站-問題提交");//如果你頁面為UTF-8,這里還要轉碼一下
$mailbody = $MailBody; //郵件內容
$mailtype = "HTML"; //郵件格式(HTML/TXT),TXT為文本郵件
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//true表示使用身份驗證,否則不使用身份驗證.
$smtp->debug = FALSE; //是否顯示發送的調試信息 TRUE發送 FALSE不發送
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);

sendMail.php代碼:
class smtp
{
/* Public Variables */
var $smtp_port; //郵件伺服器埠
var $time_out; //超時時間
var $host_name; //主機名稱
var $log_file; //日誌文件
var $relay_host; //
var $debug;
var $auth;
var $user; //用戶名
var $pass; //密碼
var $sock;
/* Constractor */
function smtp($relay_host, $smtp_port,$auth,$user,$pass)
{
// echo $relay_host." ".$smtp_port." ".$auth." ".$user." ".$pass;
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30;//is used in fsockopen()
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost";//is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}

/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
}
else {
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
return $sent;
}

/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo)) {
return $this->smtp_error("sending HELO command");
}
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
return $this->smtp_error("sending HELO command");
}
}
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom()) {
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}
if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}

function smtp_sockopen($address)
{
if ($this->relay_host == "") {
return $this->smtp_sockopen_mx($address);
} else {
return $this->smtp_sockopen_relay();
}
}

function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;
}

function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) {
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}

function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}

function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}

function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response)) {
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}

function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}

function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}

function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "") {
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}

function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
return $address;
}

function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}

function smtp_debug($message)
{
if ($this->debug) {
//echo $message;
}
}
}

㈡ 請問一下,PHP配置SMTP怎麼弄

PHPMailer的獲取:

PHPMailer項目地址:PHPMailer 使用git命令克隆到本地,或直接在該項目頁面的右下方點擊「 Download ZIP 」即可獲取到完整的PHPMailer代碼包,再到本地解壓即可。

步驟一:使我們的QQ郵箱能夠發送郵件

這里怎麼說能夠發送郵件呢?其實我們的郵箱都是可以發送郵件的,但是要實現在我們的網站中發送郵件,那就要設置一下我們的QQ郵箱了,因為此時我們的網站現在是作為一個第三方客戶端存在的。

步驟一:使我們的QQ郵箱能夠發送郵件

這里怎麼說能夠發送郵件呢?其實我們的郵箱都是可以發送郵件的,但是要實現在我們的網站中發送郵件,那就要設置一下我們的QQ郵箱了,因為此時我們的網站現在是作為一個第三方客戶端存在的

  • 由於待會我們用到的是SMTP伺服器來發送,在這里建議把前面的兩項開啟了!當你點擊開啟的時候,它會提示:

  • <?phprequire_once("./functions.php");$flag=sendMail('[email protected]','lsgo在線通知','恭喜你成功加入LSGO實驗室,開啟你的學習之旅吧!');if($flag){echo"發送郵件成功!";
    }else{echo"發送郵件失敗!";
    }?>

    ㈢ php怎麼通過第三方郵件伺服器來發送郵件

    用 PHPMailer ,這是一個郵件發送插件,到網上下載一個,具體的使用官網有方法的,很簡單。
    swiftMailer 也可以的。
    php自帶的mailer方法需要系統的支持,如果是linux的話可以直接使用,而windows就麻煩了,就用上面說的兩個插件中的任何一個就行了,

    ㈣ Postfix郵件伺服器和PHP配合

    不知道您為什麼要自己搭建郵件伺服器+web郵箱系統。對新手而言,是一件挺有挑戰性的事情。
    郵件伺服器一般我們會考慮網路上很多免費的,它們一般技術成熟,伺服器穩定,而且都是免費的。您架設的,質量上不一定比它們更好。
    而web郵箱管理系統,目前也有很多。對今天的用戶而言,也沒有太多吸引力,因為有很多的替代品。微軟的outlook,國產的foxmail都有多年的歷史,也很優秀。而現在移動互聯網時代,手機App也很有優勢。
    我猜測,您是不是想讓會員在站內發簡訊?這跟郵件是兩碼事。
    或者,您只是想通過php系統,給會員的郵箱發郵件?這用不著您架設郵件伺服器。
    當然,您可能愛上了Postfix,因為偶爾得到一個別致的領帶胸針,最後為它配了一整套的西裝革履也有可能。
    好吧,我來回答您的問題。
    1、如何對Postfix收到郵件進行管理?
    您需要編寫基本的兩個程序,收和發。收和發的代碼,比比皆是,代碼並不復雜。但是您要弄清楚架構。
    您的郵件伺服器和郵件用戶代理伺服器(會員系統)在同一個主機上,但您得想成是兩個服務,兩個系統。就是說,您收郵件時候,讀取到郵件後,將數據存到會員系統的mysql上。這個郵件在這台伺服器上實際上有兩份了。一般伺服器軟體不會用到mysql,郵件以其他形式在硬碟上存儲
    發郵件,您可以通過您Postfix提供的smtp服務往外發。數據您自己通過php程序保留一份,在您會員系統的mysql里。Postfix沒必要保留發出去的郵件。
    2.mysql在這裡面的角色是不是只管理用戶的帳號密碼信息?

    如上所述,mysql當然要保留用戶的帳號密碼信息。但不僅如此,要保留發件的內容,還要放收到的郵件內容。
    3.對於新手來說怎樣做最容易達到預期效果。

    萬能的網路,一切用現成的就好。
    您找到了Postfix,這是郵件伺服器。這個架設也不難,網上教程比比皆是。
    如果只想做郵件,不想其他的,您搜一個免費的Webmail在線郵件系統就好了。英文的較多,自己做一下漢化。PostfixAdmin可以研究下,它可以和Postfix實現mysql數據共享。
    中文的,extmail比較有名,它是一個套件,什麼都有,包括Postfix,拿來研究下直接用,無需二次開發。

    ㈤ 用PHP做一個郵件系統 不知道怎麼下手

    你要做的話,其實就是郵件的保存了,當然附件是保存在伺服器上,這個上傳就是了。
    內容的話,看你是保存資料庫還是保存文本了,其實兩者都是數據源。如果要穩定或者是以後開發的 方便的話,選擇資料庫吧。
    另外SMTP是郵件的接收協議,POP3是郵件的發送協議,一般來說,我們是用的POP3和STMP組合,這個是需要單獨的配置伺服器的。PHP只是通過MAIL來鏈接這兩個伺服器進行郵件的發送和接收工作。

    ㈥ php調用jmail組建發郵件,代碼貼不出來,

    <?
    class Jmail
    {

    public $Username; //郵局用戶名

    public $Password; //密碼

    public $FormName ; //發件人姓名

    public $From ; //發件人地址

    public $Addrecipient ; //收件人地址

    public $Ttile ; //郵件標題

    public $Content; //郵件內容

    public $Smtp; //郵件伺服器

    function Send(){

    $Jmail = new com("Jmail.Message"); //實例化一個Jmail對象

    $Jmail->SiLent=true; //設置成True的話Jmail不會提示錯誤只會返回True和False

    $Jmail->LogGing = false; //是否開啟日誌

    $Jmail->CharSet = "GB2312"; //設定字元串編碼

    $Jmail->ContentType = "Text/html"; //郵件的格式為HTML格式

    $Jmail->MailServerUsername = $this->Username; //發信箱用戶名

    $Jmail->MailServerPassword = $this->Password; //發信箱密碼

    $Jmail->FromName = $this->FromName; //發件人姓名

    $Jmail->From = $this->From; //發件人地址

    $Jmail->AddRecipient($this->Addrecipient); //收件人地址

    $Jmail->Subject = $this->Title;//Email標題

    $Jmail->Body = $this->Content; //Email正文

    $JmailError = $Jmail->Send($this->Smtp); //Smtp伺服器

    if($JmailError){ //判斷郵件是否發送成功
    return true;
    }else{
    return false;
    }

    }

    }

    //這里是調用代碼
    $jmail = new Jmail();
    $jmail->Username = "lwf0757";
    $jmail->Password = "0757";
    $jmail->FromName = "梁";
    $jmail->From = "[email protected]";
    $jmail->Addrecipient = "[email protected]";
    $jmail->Title = "這是標題";
    $jmail->Content = "這是內容";
    $jmail->Smtp = "smtp.163.com";
    if($jmail->Send()){
    echo "成功哦!";
    }else{
    echo "失敗哦!";
    }
    ?>

    ㈦ 使用Foxmail如何搭建本地SMTP伺服器,用於測試PHP發送郵件功能。

    foxmail是客戶端軟體,直接用server 2003的pop3服務就可以搭建smtp伺服器了。

    ㈧ 用hmailserver+PHP+mysql建了一個郵件系統。60多帳號,全用OE客戶端.有部分可以收,有部分收不到

    自己的郵件伺服器很難保證郵件的到達率,建議使用第三方郵件服務提供商(ESP)

    Amazon SES (http://aws.amazon.com/ses/)
    PostMark (http://www.postmarkapp.com/)
    CritSend (http://www.critsend.com/)
    SendGrid (http://sendgrid.com/)
    SocketLabs (http://www.socketlabs.com/)
    MailChimp (http://www.mailchimp.com/)

    ㈨ php發送郵件的問題:php怎麼才能發送郵件呢使用自帶的函數,應該怎樣設置相應的郵件伺服器

    首先,我不想給phpmailer這個東西做廣告,但是我確實使用的這個東西,很費解。

    1. 下載一個phpmailer類,裡面主要的是三個文件class.phpmailer.phpclass.pop3.phpclass.smtp.php

    2. 將這三個文件放到同一個文件夾.eg:papmailer

    3. 申請一個網路郵件伺服器(我用的是163伺服器)

    4. 編寫發送郵件代碼如下

    5. /**
      *發送郵件
      *@paramunknown_type$sendto_email接收人Email
      *@paramunknown_type$subject郵件主題
      *@paramunknown_type$body郵件內容
      *@paramunknown_type$user_name接受人姓名
      */
      functionsend_email($sendto_email,$subject,$body,$user_name){
      require_once"phpmailer/class.phpmailer.php";
      $mail=newPHPMailer();//創建類對象
      $mail->IsSMTP();
      $mail->Host="smtp.163.com";//SMTPservers使用163伺服器,郵件smtp伺服器
      $mail->SMTPAuth=true;//turnonSMTPauthentication
      $mail->Username="你申請的163郵箱帳號";//SMTPusername注意:普通郵件認證不需要加@域名
      $mail->Password="163郵箱密碼";//SMTPpassword
      $mail->From="發件人郵箱,可以使用上面163郵箱";//發件人郵箱
      $mail->FromName="發件人名稱,自己隨意命名";//發件人

      $mail->CharSet="utf8";//這里指定字元集!
      $mail->Encoding="base64";
      $mail->AddAddress($sendto_email,$user_name);//收件人郵箱和姓名
      $mail->IsHTML(true);//sendasHTML
      //郵件主題
      $mail->Subject=$subject;
      //郵件內容
      $mail->Body=$body;

      $mail->AltBody="text/html";
      if(!$mail->Send()){
      return$mail->ErrorInfo;
      }else{
      returntrue;
      }
      }

    ㈩ php怎麼實現發送郵件

    PHP發送郵件是「非常的簡單」 因為他提供了mail()函數直接發送,但配置相當麻煩 (1)通過mail()函數發送郵件 mail() 配置PHP.ini 郵件信息 需要類似sendmail這樣的組件支持 (2)通過socket通訊,使用SMTP傳輸 socket連接->SMTP通訊->獲取通訊消息->發送 mail函數的使用 mail() 函數允許您從腳本中直接發送電子郵件。 如果郵件的投遞被成功地接收,則返回 true,否則返回 mail(to,subject,message,headers,parameters) socket方式發送原理 給你一個別人寫好的類 用法在下面 本人經測試很多網站都不提供免費的smtp服務(126、sina、netease 這幾個試過了),騰訊郵箱支持此功能。 用法: <? require_once ('email.class.php'); //########################################## $smtpserver = "smtp.163.com";//SMTP伺服器 $smtpserverport =25;//SMTP伺服器埠 $smtpusermail = "";//SMTP伺服器的用戶郵箱 $smtpemailto = "";//發送給誰 $smtpuser = "";//SMTP伺服器的用戶帳號 $smtppass = "";//SMTP伺服器的用戶密碼 $mailsubject = "PHP100測試郵件系統";//郵件主題 $mailbody = "<h1> 這是一個測試程序 PHP100.com </h1>";//郵件內容 $mailtype = "HTML";//郵件格式(HTML/TXT),TXT為文本郵件 ########################################## $smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//這裡面的一個true是表示使用身份驗證,否則不使用身份驗證. $smtp->debug = FALSE;//是否顯示發送的調試信息 $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype); ?> 郵件發送類 <? class smtp { /* Public Variables */ var $smtp_port; var $time_out; var $host_name; var $log_file; var $relay_host; var $debug; var $auth; var $user; var $pass; /* Private Variables */ var $sock; /* Constractor */ function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass) { $this->debug = FALSE; $this->smtp_port = $smtp_port; $this->relay_host = $relay_host; $this->time_out = 30; //is used in fsockopen() # $this->auth = $auth;//auth $this->user = $user; $this->pass = $pass; # $this->host_name = "localhost"; //is used in HELO command $this->log_file =""; $this->sock = FALSE; } /* Main Function */ function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "") { $mail_from = $this->get_address($this->strip_comment($from)); $body = ereg_replace("(^|(\r\n))(\\.)", "\\1.\\3", $body); $header .= "MIME-Version:1.0\r\n"; if($mailtype=="HTML"){ $header .= "Content-Type:text/html\r\n"; } $header .= "To: ".$to."\r\n"; if ($cc != "") { $header .= "Cc: ".$cc."\r\n"; } $header .= "From: $from<".$from.">\r\n"; $header .= "Subject: ".$subject."\r\n"; $header .= $additional_headers; $header .= "Date: ".date("r")."\r\n"; $header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n"; list($msec, $sec) = explode(" ", microtime()); $header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n"; $TO = explode(",", $this->strip_comment($to)); if ($cc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($cc))); } if ($bcc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($bcc))); } $sent = TRUE; foreach ($TO as $rcpt_to) { $rcpt_to = $this->get_address($rcpt_to); if (!$this->smtp_sockopen($rcpt_to)) { $this->log_write("Error: Cannot send email to ".$rcpt_to."\n"); $sent = FALSE; continue; } if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) { $this->log_write("E-mail has been sent to <".$rcpt_to.">\n"); } else { $this->log_write("Error: Cannot send email to <".$rcpt_to.">\n"); $sent = FALSE; } fclose($this->sock); $this->log_write("Disconnected from remote host\n"); } echo "<br>"; echo $header; return $sent; } /* Private Functions */ function smtp_send($helo, $from, $to, $header, $body = "") { if (!$this->smtp_putcmd("HELO", $helo)) { return $this->smtp_error("sending HELO command"); } #auth if($this->auth){ if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) { return $this->smtp_error("sending HELO command"); } if (!$this->smtp_putcmd("", base64_encode($this->pass))) { return $this->smtp_error("sending HELO command"); } } # if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) { return $this->smtp_error("sending MAIL FROM command"); } if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) { return $this->smtp_error("sending RCPT TO command"); } if (!$this->smtp_putcmd("DATA")) { return $this->smtp_error("sending DATA command"); } if (!$this->smtp_message($header, $body)) { return $this->smtp_error("sending message"); } if (!$this->smtp_eom()) { return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]"); } if (!$this->smtp_putcmd("QUIT")) { return $this->smtp_error("sending QUIT command"); } return TRUE; } function smtp_sockopen($address) { if ($this->relay_host == "") { return $this->smtp_sockopen_mx($address); } else { return $this->smtp_sockopen_relay(); } } function smtp_sockopen_relay() { $this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); return FALSE; } $this->log_write("Connected to relay host ".$this->relay_host."\n"); return TRUE;; } function smtp_sockopen_mx($address) { $domain = ereg_replace("^.+@([^@]+)$", "\\1", $address); if (!@getmxrr($domain, $MXHOSTS)) { $this->log_write("Error: Cannot resolve MX \"".$domain."\"\n"); return FALSE; } foreach ($MXHOSTS as $host) { $this->log_write("Trying to ".$host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Warning: Cannot connect to mx host ".$host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); continue; } $this->log_write("Connected to mx host ".$host."\n"); return TRUE; } $this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n"); return FALSE; } function smtp_message($header, $body) { fputs($this->sock, $header."\r\n".$body); $this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> ")); return TRUE; } function smtp_eom() { fputs($this->sock, "\r\n.\r\n"); $this->smtp_debug(". [EOM]\n"); return $this->smtp_ok(); } function smtp_ok() { $response = str_replace("\r\n", "", fgets($this->sock, 512)); $this->smtp_debug($response."\n"); if (!ereg("^[23]", $response)) { fputs($this->sock, "QUIT\r\n"); fgets($this->sock, 512); $this->log_write("Error: Remote host returned \"".$response."\"\n"); return FALSE; } return TRUE; } function smtp_putcmd($cmd, $arg = "") { if ($arg != "") { if($cmd=="") $cmd = $arg; else $cmd = $cmd." ".$arg; } fputs($this->sock, $cmd."\r\n"); $this->smtp_debug("> ".$cmd."\n"); return $this->smtp_ok(); } function smtp_error($string) { $this->log_write("Error: Error occurred while ".$string.".\n"); return FALSE; } function log_write($message) { $this->smtp_debug($message); if ($this->log_file == "") { return TRUE; } $message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message; if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) { $this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n"); return FALSE; } flock($fp, LOCK_EX); fputs($fp, $message); fclose($fp); return TRUE; } function strip_comment($address) { $comment = "\\([^()]*\\)"; while (ereg($comment, $address)) { $address = ereg_replace($comment, "", $address); } return $address; } function get_address($address) { $address = ereg_replace("([ \t\r\n])+", "", $address); $address = ereg_replace("^.*<(.+)>.*$", "\\1", $address); return $address; } function smtp_debug($message) { if ($this->debug) { echo $message."<br>"; } } function get_attach_type($image_tag) { // $filedata = array(); $img_file_con=fopen($image_tag,"r"); unset($image_data); while ($tem_buffer=AddSlashes(fread($img_file_con,filesize($image_tag)))) $image_data.=$tem_buffer; fclose($img_file_con); $filedata['context'] = $image_data; $filedata['filename']= basename($image_tag); $extension=substr($image_tag,strrpos($image_tag,"."),strlen($image_tag)-strrpos($image_tag,".")); switch($extension){ case ".gif": $filedata['type'] = "image/gif"; break; case ".gz": $filedata['type'] = "application/x-gzip"; break; case ".htm": $filedata['type'] = "text/html"; break; case ".html": $filedata['type'] = "text/html"; break; case ".jpg": $filedata['type'] = "image/jpeg"; break; case ".tar": $filedata['type'] = "application/x-tar"; break; case ".txt": $filedata['type'] = "text/plain"; break; case ".zip": $filedata['type'] = "application/zip"; break; default: $filedata['type'] = "application/octet-stream"; break; } return $filedata; } } ?>

熱點內容
自動編譯div 發布:2025-01-12 18:51:06 瀏覽:659
手機路由器如何登陸密碼 發布:2025-01-12 18:35:41 瀏覽:464
電光貓無法連接伺服器是什麼原因 發布:2025-01-12 18:32:58 瀏覽:512
迷你世界測試服的密碼從哪裡打開 發布:2025-01-12 18:25:32 瀏覽:110
我的世界手游tis伺服器 發布:2025-01-12 18:24:28 瀏覽:585
青海省分布式伺服器雲主機 發布:2025-01-12 18:12:03 瀏覽:476
英雄聯盟安卓手機版怎麼切換 發布:2025-01-12 18:10:53 瀏覽:381
q5尊享時尚型哪些配置 發布:2025-01-12 18:05:41 瀏覽:229
安卓版本哪裡下載 發布:2025-01-12 18:05:39 瀏覽:557
mc伺服器搭建搜不到 發布:2025-01-12 17:57:37 瀏覽:19