📄 swift.php
字号:
<?php/** * Swift Mailer: A Flexible PHP Mailer Class. * * Current functionality: * * * Send uses one single connection to the SMTP server * * Doesn't rely on mail() * * Custom Headers * * Unlimited redundant connections (can be mixed type) * * Connection cycling & load balancing * * Sends Multipart messages, handles encoding * * Sends Plain-text single-part emails * * Fast Cc and Bcc handling * * Immune to rejected recipients (sends to subsequent recipients w/out error) * * Set Priority Level * * Request Read Receipts * * Unicode UTF-8 support with auto-detection * * Auto-detection of SMTP/Sendmail details based on PHP & server configuration * * Batch emailing with multiple To's or without * * Support for multiple attachments * * Sendmail (or other binary) support * * Pluggable SMTP Authentication (LOGIN, PLAIN, MD5-CRAM, POP Before SMTP) * * Secure Socket Layer connections (SSL) * * Transport Layer security (TLS) - Gmail account holders! * * Send mail with inline embedded images easily (or embed other file types)! * * Loadable plugin support with event handling features * * @package Swift * @version 2.1.17 * @author Chris Corbyn * @date 18th October 2006 * @license http://www.gnu.org/licenses/lgpl.txt Lesser GNU Public License * * @copyright Copyright © 2006 Chris Corbyn - All Rights Reserved. * @filesource * * ----------------------------------------------------------------------- * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to * * The Free Software Foundation, Inc., * 51 Franklin Street, * Fifth Floor, * Boston, * MA 02110-1301 USA * * "Chris Corbyn" <chris@w3style.co.uk> * */if (!defined('SWIFT_VERSION')) define('SWIFT_VERSION', '2.1.17');/** * Swift Plugin Interface. Describes the methods which plugins should implement * @package Swift */interface Swift_IPlugin{ /** * Required Properties * * private SwiftInstance; * public pluginName; */ /** * Loads an instance of Swift to the Plugin * @param object SwiftInstance * @return void */ public function loadBaseObject(&$object); /** * Optional Methods to implement * * public function onLoad(); * public function onClose(); * public function onFail(); * public function onError(); * public function onBeforeSend(); * public function onSend(); * public function onBeforeCommand(); * public function onCommand(); * public function onLog(); * public function onAuthenticate(); * public function onFlush(); * public function onResponse(); */}/** * Swift Authenticator Interface. Describes the methods which authenticators should implement * @package Swift */interface Swift_IAuthenticator{ /** * Required Properties * private SwiftInstance; * public serverString; */ /** * Loads an instance of Swift to the Plugin * @param object SwiftInstance * @return void */ public function loadBaseObject(&$object); /** * Executes the logic in the authentication mechanism * @param string username * @param string password * @return bool successful */ public function run($username, $password); }/** * Swift Connection Handler Interface. * Describes the methods which connection handlers should implement * @package Swift */interface Swift_IConnection{ /** * Required properties * * public readHook; * public writeHook; * public error */ /** * Establishes a connection with the MTA * @return bool connected */ public function start(); /** * Closes the connection with the MTA * @return void */ public function stop(); /** * Returns a boolean value TRUE if the connection is active. * @return bool connected */ public function isConnected();}/** * Swift Mailer Class. * Accepts connections to an MTA and deals with the sending and processing of * commands and responses. * @package Swift */class Swift{ /** * Plugins container * @var array plugins * @private */ private $plugins = array(); private $esmtp = false; private $_8bitmime = false; private $autoCompliance = false; /** * Whether or not Swift should send unique emails to all "To" * recipients or just bulk them together in the To header. * @var bool use_exact */ private $useExactCopy = false; private $domain = 'SwiftUser'; private $mimeBoundary; private $mimeWarning; /** * MIME Parts container * @var array parts * @private */ private $parts = array(); /** * Attachment data container * @var array attachments * @private */ private $attachments = array(); /** * Inline image container * @var array image parts * @private */ private $images = array(); /** * Response codes expected for commands * $command => $code * @var array codes * @private */ private $expectedCodes = array( 'ehlo' => 250, 'helo' => 250, 'mail' => 250, 'rcpt' => 250, 'data' => 354 ); /** * Blind-carbon-copy address container * @var array addresses */ private $Bcc = array(); /** * Carbon-copy address container * @var array addresses */ private $Cc = array(); /** * The address any replies will go to * @var string address */ private $replyTo; /** * The addresses we're sending to * @var string address */ private $to = array(); /** * The sender of the email * @var string sender */ private $from; /** * Priority value 1 (high) to 5 (low) * @var int priority (1-5) */ private $priority = 3; /** * Whether a read-receipt is required * @var bool read receipt */ private $readReceipt = false; /** * The max number of entires that can exist in the log * (saves memory) * @var int log size */ private $maxLogSize = 30; /** * The address to which bounces are sent * @var string Return-Path: */ private $returnPath; /** * Connection object (container holding a socket) * @var object connection */ public $connection; /** * Authenticators container * @var array authenticators */ public $authenticators = array(); public $authTypes = array(); /** * Holds the username used in authentication (if any) * @var string username */ public $username; /** * Holds the password used in authentication (if any) * @var string password */ public $password; public $charset = "ISO-8859-1"; private $userCharset = false; /** * Boolean value representing if Swift has failed or not * @var bool failed */ public $failed = false; /** * If Swift should clear headers etc automatically * @var bool autoFlush */ public $autoFlush = true; /** * Numeric code from the last MTA response * @var int code */ public $responseCode; /** * Keyword of the command being sent * @var string keyword */ public $commandKeyword; /** * Last email sent or email about to be sent (dependant on location) * @var array commands */ public $currentMail = array(); /** * Email headers * @var string headers */ public $headers; public $currentCommand = ''; /** * Errors container * @var array errors */ public $errors = array(); /** * Log container * @var array transactions */ public $transactions = array(); public $lastTransaction; public $lastError; /** * The very most recent response received from the MTA * @var string response */ public $lastResponse; /** * The total number of failed recipients * @var int failed */ private $failCount = 0; /** * Number of failed recipients for this email * @var int failed */ private $subFailCount = 0; /** * Number of addresses expected to pass this email * @var int recipients */ private $numAddresses; /** * Container for any recipients rejected * @var array failed addresses */ private $failedAddresses = array(); /** * Number of commands which will be skipped */ public $ignoreCommands = 0; /** * Number of commands skipped thus far */ private $skippedCommands = 0; /** * The encoding mode to use in headers (default base64) * @var char mode */ private $headerEncoding = 'B'; /** * Swift Constructor * @param object Swift_IConnection * @param string user_domain, optional */ public function __construct(Swift_IConnection &$object, $domain=false) { if (!$domain) $domain = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'SwiftUser'; $this->domain = $domain; $this->connection =& $object; $this->connect(); // * Hey this library is FREE so it's not much to ask ;) But if you really do want to // remove this header then go ahead of course... what's GPL for? :P $this->headers = "X-Mailer: Swift ".SWIFT_VERSION." by Chris Corbyn\r\n"; $this->mimeWarning = "This part of the E-mail should never be seen. If\r\n". "you are reading this, consider upgrading your e-mail\r\n". "client to a MIME-compatible client."; } /** * Connect to the server * @return bool connected */ public function connect() { if (!$this->connection->start()) { $this->fail(); $error = 'Connection to the given MTA failed.'; if (!empty($this->connection->error)) $error .= ' The Connection Interface said: '.$this->connection->error; $this->logError($error, 0); return false; } else { $this->handshake(); return true; } } /** * Returns TRUE if the connection is active. */ public function isConnected() { return $this->connection->isConnected(); } /** * Sends the standard polite greetings to the MTA and then * identifies the MTA's capabilities */ public function handshake() { $this->commandKeyword = ""; //What did the server greet us with on connect? $this->logTransaction(); if ($this->supportsESMTP($this->lastResponse)) { //Just being polite $list = $this->command("EHLO {$this->domain}\r\n"); $this->check8BitMime($this->lastResponse); $this->getAuthenticationMethods($list); $this->esmtp = true; } else $this->command("HELO {$this->domain}\r\n"); } /** * Check if the server allows 8bit emails to be sent without quoted-printable encoding * @param string EHLO response */ private function check8BitMime($string) { if (strpos($string, '8BITMIME')) $this->_8bitmime = true; } /** * Checks for Extended SMTP support * @param string MTA greeting * @return bool ESMTP * @private */ private function supportsESMTP($greeting) { //Not mentiioned in RFC 2821 but this how it's done if (strpos($greeting, 'ESMTP')) return true; else return false; } /** * Set the maximum num ber of entries in the log * @param int size */ public function setMaxLogSize($size) { $this->maxLogSize = (int) $size; } /** * Sets the priority level of the email * This must be 1 to 5 where 1 is highest * @param int priority */ public function setPriority($level) { $level = (int) $level; if ($level < 1) $level = 1; if ($level > 5) $level = 5; switch ($level) { case 1: case 2: $this->addHeaders("X-Priority: $level\r\nX-MSMail-Priority: High"); break; case 4: case 5: $this->addHeaders("X-Priority: $level\r\nX-MSMail-Priority: Low"); break; case 3: default: $this->addHeaders("X-Priority: $level\r\nX-MSMail-Priority: Normal"); } } /** * Set the encoding to use in headers * @param string mode */ public function setHeaderEncoding($mode='B') { switch (strtoupper($mode)) { case 'Q': case 'QP': case 'QUOTED-PRINTABLE': $this->headerEncoding = 'Q'; break; default: $this->headerEncoding = 'B'; } } /** * Set the return path address (Bounce detection) * @param string address */ public function setReturnPath($address) { $this->returnPath = $this->getAddress($address); } /** * Request a read receipt from all recipients * @param bool request receipt */ public function requestReadReceipt($request=true) { $this->readReceipt = (bool) $request; } /** * Set the character encoding were using * @param string charset */ public function setCharset($string) { $this->charset = $string; $this->userCharset = $string; } /** * Whether or not Swift should send unique emails to all To recipients * @param bool unique */ public function useExactCopy($use=true) { $this->useExactCopy = (bool) $use; } /** * Get the return path recipient */ public function getReturnPath() { return $this->returnPath; } /** * Get the sender */ public function getFromAddress() { return $this->from; } /** * Get Cc recipients */ public function getCcAddresses() { return $this->Cc; } /** * Get Bcc addresses */ public function getBccAddresses() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -