?? class.phpmailer.php
字號:
// Choose the mailer if($this->Mailer == "sendmail") { if(!$this->sendmail_send($header, $body)) return false; } elseif($this->Mailer == "mail") { if(!$this->mail_send($header, $body)) return false; } elseif($this->Mailer == "smtp") { $this -> nb_try=0; $this -> Recup_code_error = null; $hosts = explode(";", $this->Host); $sendOKAY=false; while($this -> nb_try < count($hosts) && !$sendOKAY ) { if ($this->Debug_Roll) echo "<br><br> ---> TRY : ".$this -> nb_try; if(!$this->smtp_send($header, $body)){ if (($this -> Recup_code_error == "550") && ($this -> nb_try < count($hosts)) ){ // Try again if ($this->Debug_Roll) echo "<br> --->>> Try again "; }else{ if ($this->Debug_Roll) echo "<br> --->>> ERROR"; return false; } }else{ //Envoie reussit -> SORTIR BOUCLE $sendOKAY=true; //return true it's the same } } } else { $this->error_handler(sprintf("%s mailer is not supported", $this->Mailer)); return false; } return true; } /** * Sends mail using the $Sendmail program. Returns bool. * @private * @returns bool */ function sendmail_send($header, $body) { if ($this->Sender != "") $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender); else $sendmail = sprintf("%s -oi -t", $this->Sendmail); if(!@$mail = popen($sendmail, "w")) { $this->error_handler(sprintf("Could not execute %s", $this->Sendmail)); return false; } fputs($mail, $header); fputs($mail, $body); pclose($mail); return true; } /** * Sends mail using the PHP mail() function. Returns bool. * @private * @returns bool */ function mail_send($header, $body) { //$to = substr($this->addr_append("To", $this->to), 4, -2); // Cannot add Bcc's to the $to $to = $this->to[0][0]; // no extra comma for($i = 1; $i < count($this->to); $i++) $to .= sprintf(",%s", $this->to[$i][0]); if ($this->Sender != "" && PHP_VERSION >= "4.0") { $old_from = ini_get("sendmail_from"); ini_set("sendmail_from", $this->Sender); } if ($this->Sender != "" && PHP_VERSION >= "4.0.5") { // The fifth parameter to mail is only available in PHP >= 4.0.5 $params = sprintf("-oi -f %s", $this->Sender); $rt = @mail($to, $this->Subject, $body, $header, $params); } else { $rt = @mail($to, $this->Subject, $body, $header); } if (isset($old_from)) ini_set("sendmail_from", $old_from); if(!$rt) { $this->error_handler("Could not instantiate mail()"); return false; } return true; } /** * Sends mail via SMTP using PhpSMTP (Author: * Chris Ryan). Returns bool. Returns false if there is a * bad MAIL FROM, RCPT, or DATA input. * @private * @returns bool */ function smtp_send($header, $body) { // Include SMTP class code, but not twice include_once("class.smtp.php"); // Load code only if asked $smtp = new SMTP; $smtp->do_debug = $this->SMTPDebug; // Try to connect to all SMTP servers $hosts = explode(";", $this->Host); //$this -> Curent_SMTP_Server = $this -> Curent_SMTP_Server + $this -> nb_try; if ($this->Debug_Roll) echo "<br>Nombre de HOST :".count($hosts)."<br><br>"; if ($this->Debug_Roll) echo "<br>Curent_SMTP_Server : ".$this -> Curent_SMTP_Server; $this -> Curent_SMTP_Server= ($this -> Curent_SMTP_Server + 1) % count($hosts); if ($this->Debug_Roll) echo "<br><br>Curent_SMTP_Server : ".$this -> Curent_SMTP_Server."<br>"; if ($this->Debug_Roll) print_r ($hosts); if (count($hosts)>1){ for ($i=0;$i<$this -> Curent_SMTP_Server;$i++){ $the_shift = array_shift($hosts); array_push($hosts, $the_shift); } } if ($this->Debug_Roll) echo "<br>"; if ($this->Debug_Roll) print_r ($hosts); $index = 0; $connection = false; $smtp_from = ""; $bad_rcpt = array(); $e = ""; // Retry while there is no connection while($this -> nb_try < count($hosts) && $connection == false) { $this -> nb_try++; if(strstr($hosts[$index], ":")) list($host, $port) = explode(":", $hosts[$index]); else { $host = $hosts[$index]; $port = $this->Port; } if ($this->Debug_Roll) echo "<br> --> Host_USED: $host Port_USED: $port --->"; if($smtp->Connect($host, $port, $this->Timeout)){ $connection = true; if ($this->Debug_Roll) echo "<br>OK<br>"; }else{ //printf("<br><b> %s </b> :: host could not connect<br>", $hosts[$index]); //debug only if ($this->Debug_Roll) echo "<br>NO<br>"; $this -> Curent_SMTP_Server= $this -> Curent_SMTP_Server+1; } $index++; } if(!$connection) { //echo "SMTP Error: could not connect to SMTP host server(s) ::: $host"; $this->error_handler("SMTP Error: could not connect to SMTP host server(s)"); return false; } // Must perform HELO before authentication $smtp->Hello($this->Helo); // If user requests SMTP authentication /*if($this->SMTPAuth) { if(!$smtp->Authenticate($this->Username, $this->Password)) { $this->error_handler("SMTP Error: Could not authenticate"); //echo "<br>SMTP Error: Could not authenticate"; return false; } }*/ if ($this->Sender == "") $smtp_from = $this->From; else $smtp_from = $this->Sender; if(!$smtp->Mail(sprintf("<%s>", $smtp_from))) { $e = sprintf("SMTP Error: From address [%s] failed", $smtp_from); $this->error_handler($e); //echo "<br>$e"; return false; } // Attempt to send attach all recipients for($i = 0; $i < count($this->to); $i++) { if(!$smtp->Recipient(sprintf("<%s>", $this->to[$i][0]))){ if ($smtp -> code_error != 550){ //Relaying denied $bad_rcpt[] = $this->to[$i][0]; }else{ if ($this->Debug_Roll) echo "<br><br> Relaying denied !!!"; if ($this->Debug_Roll) echo "<br> --> Host_USED: $host Port_USED: $port --->"; if ($this->Debug_Roll) echo "<br>Curent_SMTP_Server : ".$this -> Curent_SMTP_Server; if ($this->Debug_Roll) echo "<br> NB TRY : ".$this -> nb_try."<br>"; if ($this->Debug_Roll) print_r ($hosts); $this -> Recup_code_error = $smtp -> code_error; return false; } } } for($i = 0; $i < count($this->cc); $i++) { if(!$smtp->Recipient(sprintf("<%s>", $this->cc[$i][0]))) $bad_rcpt[] = $this->cc[$i][0]; } for($i = 0; $i < count($this->bcc); $i++) { if(!$smtp->Recipient(sprintf("<%s>", $this->bcc[$i][0]))) $bad_rcpt[] = $this->bcc[$i][0]; } // Create error message if(count($bad_rcpt) > 0) { for($i = 0; $i < count($bad_rcpt); $i++) { if($i != 0) $e .= ", "; $e .= $bad_rcpt[$i]; } $e = sprintf("SMTP Error: The following recipients failed [%s]", $e); $this->error_handler($e); //echo "<br>$e"; return false; } if(!$smtp->Data(sprintf("%s%s", $header, $body))) { $this->error_handler("SMTP Error: Data not accepted"); //echo "<br>SMTP Error: Data not accepted"; return false; } $smtp->Quit(); return true; } ///////////////////////////////////////////////// // MESSAGE CREATION METHODS ///////////////////////////////////////////////// /** * Creates recipient headers. Returns string. * @private * @returns string */ function addr_append($type, $addr) { $addr_str = ""; $addr_str .= sprintf("%s: \"%s\" <%s>", $type, addslashes($addr[0][1]), $addr[0][0]); if(count($addr) > 1) { for($i = 1; $i < count($addr); $i++) { $addr_str .= sprintf(", \"%s\" <%s>", addslashes($addr[$i][1]), $addr[$i][0]); } $addr_str .= "\r\n"; } else $addr_str .= "\r\n"; return($addr_str); } /** * Wraps message for use with mailers that do not * automatically perform wrapping and for quoted-printable. * Original written by philippe. Returns string. * @private * @returns string */ function wordwrap($message, $length, $qp_mode = false) { if ($qp_mode) $soft_break = " =\r\n"; else $soft_break = "\r\n"; $message = $this->fix_eol($message); if (substr($message, -1) == "\r\n") $message = substr($message, 0, -1); $line = explode("\r\n", $message); $message = ""; for ($i=0 ;$i < count($line); $i++) { $line_part = explode(" ", $line[$i]); for ($e = 0; $e<count($line_part); $e++) { $word = $line_part[$e]; if ($qp_mode and (strlen($word) > $length)) { $space_left = $length - strlen($buf) - 1; if ($e != 0) { if ($space_left > 20) { $len = $space_left; if (substr($word, $len - 1, 1) == "=") $len--; elseif (substr($word, $len - 2, 1) == "=") $len -= 2; $part = substr($word, 0, $len); $word = substr($word, $len); $buf .= " " . $part; $message .= $buf . "=\r\n"; } else { $message .= $buf . $soft_break; } $buf = ""; } while (strlen($word) > 0) { $len = $length; if (substr($word, $len - 1, 1) == "=") $len--; elseif (substr($word, $len - 2, 1) == "=") $len -= 2; $part = substr($word, 0, $len); $word = substr($word, $len); if (strlen($word) > 0) $message .= $part . "=\r\n"; else $buf = $part; } } else { $buf_o = $buf; if ($e == 0) $buf .= $word; else $buf .= " " . $word; if (strlen($buf) > $length and $buf_o != "") { $message .= $buf_o . $soft_break; $buf = $word; } } } $message .= $buf . "\r\n"; } return ($message); } /** * Assembles message header. Returns a string if successful * or false if unsuccessful. * @private * @returns string */ function create_header() { $header = array(); $header[] = $this->received(); $header[] = sprintf("Date: %s\r\n", $this->rfc_date()); // To be created automatically by mail() if($this->Mailer != "mail") $header[] = $this->addr_append("To", $this->to); $header[] = sprintf("From: \"%s\" <%s>\r\n", addslashes($this->FromName), trim($this->From)); if(count($this->cc) > 0) $header[] = $this->addr_append("Cc", $this->cc); // sendmail and mail() extract Bcc from the header before sending if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0)) $header[] = $this->addr_append("Bcc", $this->bcc); if(count($this->ReplyTo) > 0) $header[] = $this->addr_append("Reply-to", $this->ReplyTo); // mail() sets the subject itself if($this->Mailer != "mail"){ if ($this->Subject_CharSet){ //Subject: =?shift_jis?B?k5aO0ILMg0WDRoN1g32DWINegVuDdoONg0+DiYOAgsmOUYKpgrWCxIm6?= // =?shift_jis?B?grOCog==?= //Subject: =?iso-2022-jp?B?IBskQjxMPz8hKiEqISobKEI=?= //Subject: =?shift_jis?B?k5aO0ILMg0WDRoN1g32DWINegVuDdoONg0+DiYOAgsmOUYKpgrWCxIm6?= //=?shift_jis?B?grOCog==?= //Subject: =?shift_jis?B?g2qDhYFbg1iDjINegVuC8JGXkE2CtYK9gqI $header[] = sprintf("Subject: =?%s?B?%s=?=\r\n",trim($this->CharSet), trim($this->Subject)); }else{ $header[] = sprintf("Subject: %s\r\n", trim($this->Subject)); } } $header[] = sprintf("X-Priority: %d\r\n", $this->Priority); $header[] = sprintf("X-Mailer: Mailing-List System [Version %s]\r\n", $this->Version); //$header[] = sprintf("Return-Path: %s\r\n", trim($this->From)); $header[] = sprintf("Return-Path: %s\r\n", $this -> Sender); //print_r ($header); // Add custom headers for($index = 0; $index < count($this->CustomHeader); $index++) $header[] = sprintf("%s\r\n", $this->CustomHeader[$index]); if($this->UseMSMailHeaders) $header[] = $this->AddMSMailHeaders(); $header[] = "MIME-Version: 1.0\r\n"; // Add all attachments if(count($this->attachment) > 0 || !empty($this->AltBody)) { // Set message boundary $this->boundary = "_b" . md5(uniqid(time())); // Set message subboundary for multipart/alternative $this->subboundary = "_sb" . md5(uniqid(time())); $header[] = "Content-Type: Multipart/Mixed;\r\n"; $header[] = sprintf("\tboundary=\"Boundary-=%s\"\r\n\r\n", $this->boundary); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -