Revision 533
Added by doc almost 18 years ago
| class.phpmailer.php | ||
|---|---|---|
| 1 | 1 |
<?php |
| 2 |
//////////////////////////////////////////////////// |
|
| 3 |
// PHPMailer - PHP email class |
|
| 4 |
// |
|
| 5 |
// Class for sending email using either |
|
| 6 |
// sendmail, PHP mail(), or SMTP. Methods are |
|
| 7 |
// based upon the standard AspEmail(tm) classes. |
|
| 8 |
// |
|
| 9 |
// Copyright (C) 2001 - 2003 Brent R. Matzelle |
|
| 10 |
// |
|
| 11 |
// License: LGPL, see LICENSE |
|
| 12 |
//////////////////////////////////////////////////// |
|
| 2 |
/*~ class.phpmailer.php |
|
| 3 |
.---------------------------------------------------------------------------. |
|
| 4 |
| Software: PHPMailer - PHP email class | |
|
| 5 |
| Version: 2.0.0 rc3 | |
|
| 6 |
| Contact: via sourceforge.net support pages (also www.codeworxtech.com) | |
|
| 7 |
| Info: http://phpmailer.sourceforge.net | |
|
| 8 |
| Support: http://sourceforge.net/projects/phpmailer/ | |
|
| 9 |
| ------------------------------------------------------------------------- | |
|
| 10 |
| Author: Andy Prevost (project admininistrator) | |
|
| 11 |
| Author: Brent R. Matzelle (original founder) | |
|
| 12 |
| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. | |
|
| 13 |
| Copyright (c) 2001-2003, Brent R. Matzelle | |
|
| 14 |
| ------------------------------------------------------------------------- | |
|
| 15 |
| License: Distributed under the Lesser General Public License (LGPL) | |
|
| 16 |
| http://www.gnu.org/copyleft/lesser.html | |
|
| 17 |
| This program is distributed in the hope that it will be useful - WITHOUT | |
|
| 18 |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
|
| 19 |
| FITNESS FOR A PARTICULAR PURPOSE. | |
|
| 20 |
| ------------------------------------------------------------------------- | |
|
| 21 |
| We offer a number of paid services (www.codeworxtech.com): | |
|
| 22 |
| - Web Hosting on highly optimized fast and secure servers | |
|
| 23 |
| - Technology Consulting | |
|
| 24 |
| - Oursourcing (highly qualified programmers and graphic designers) | |
|
| 25 |
'---------------------------------------------------------------------------' |
|
| 13 | 26 |
|
| 14 | 27 |
/** |
| 15 | 28 |
* PHPMailer - PHP email transport class |
| 16 | 29 |
* @package PHPMailer |
| 17 |
* @author Brent R. Matzelle
|
|
| 18 |
* @copyright 2001 - 2003 Brent R. Matzelle
|
|
| 30 |
* @author Andy Prevost
|
|
| 31 |
* @copyright 2004 - 2007 Andy Prevost
|
|
| 19 | 32 |
*/ |
| 20 |
class PHPMailer |
|
| 21 |
{
|
|
| 22 |
///////////////////////////////////////////////// |
|
| 23 |
// PUBLIC VARIABLES |
|
| 24 |
///////////////////////////////////////////////// |
|
| 25 | 33 |
|
| 26 |
/** |
|
| 27 |
* Email priority (1 = High, 3 = Normal, 5 = low). |
|
| 28 |
* @var int |
|
| 29 |
*/ |
|
| 30 |
var $Priority = 3; |
|
| 34 |
class PHPMailer {
|
|
| 31 | 35 |
|
| 32 |
/** |
|
| 33 |
* Sets the CharSet of the message. |
|
| 34 |
* @var string |
|
| 35 |
*/ |
|
| 36 |
var $CharSet = "iso-8859-1"; |
|
| 36 |
///////////////////////////////////////////////// |
|
| 37 |
// PROPERTIES, PUBLIC |
|
| 38 |
///////////////////////////////////////////////// |
|
| 37 | 39 |
|
| 38 |
/**
|
|
| 39 |
* Sets the Content-type of the message.
|
|
| 40 |
* @var string
|
|
| 41 |
*/
|
|
| 42 |
var $ContentType = "text/plain";
|
|
| 40 |
/** |
|
| 41 |
* Email priority (1 = High, 3 = Normal, 5 = low).
|
|
| 42 |
* @var int
|
|
| 43 |
*/ |
|
| 44 |
var $Priority = 3;
|
|
| 43 | 45 |
|
| 44 |
/** |
|
| 45 |
* Sets the Encoding of the message. Options for this are "8bit", |
|
| 46 |
* "7bit", "binary", "base64", and "quoted-printable". |
|
| 47 |
* @var string |
|
| 48 |
*/ |
|
| 49 |
var $Encoding = "8bit"; |
|
| 46 |
/** |
|
| 47 |
* Sets the CharSet of the message. |
|
| 48 |
* @var string |
|
| 49 |
*/ |
|
| 50 |
var $CharSet = 'iso-8859-1'; |
|
| 50 | 51 |
|
| 51 |
/**
|
|
| 52 |
* Holds the most recent mailer error message.
|
|
| 53 |
* @var string
|
|
| 54 |
*/
|
|
| 55 |
var $ErrorInfo = "";
|
|
| 52 |
/** |
|
| 53 |
* Sets the Content-type of the message.
|
|
| 54 |
* @var string |
|
| 55 |
*/ |
|
| 56 |
var $ContentType = 'text/plain';
|
|
| 56 | 57 |
|
| 57 |
/** |
|
| 58 |
* Sets the From email address for the message. |
|
| 59 |
* @var string |
|
| 60 |
*/ |
|
| 61 |
var $From = "root@localhost"; |
|
| 58 |
/** |
|
| 59 |
* Sets the Encoding of the message. Options for this are "8bit", |
|
| 60 |
* "7bit", "binary", "base64", and "quoted-printable". |
|
| 61 |
* @var string |
|
| 62 |
*/ |
|
| 63 |
var $Encoding = '8bit'; |
|
| 62 | 64 |
|
| 63 |
/**
|
|
| 64 |
* Sets the From name of the message.
|
|
| 65 |
* @var string
|
|
| 66 |
*/
|
|
| 67 |
var $FromName = "Root User";
|
|
| 65 |
/** |
|
| 66 |
* Holds the most recent mailer error message.
|
|
| 67 |
* @var string |
|
| 68 |
*/ |
|
| 69 |
var $ErrorInfo = '';
|
|
| 68 | 70 |
|
| 69 |
/** |
|
| 70 |
* Sets the Sender email (Return-Path) of the message. If not empty, |
|
| 71 |
* will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
|
| 72 |
* @var string |
|
| 73 |
*/ |
|
| 74 |
var $Sender = ""; |
|
| 71 |
/** |
|
| 72 |
* Sets the From email address for the message. |
|
| 73 |
* @var string |
|
| 74 |
*/ |
|
| 75 |
var $From = 'root@localhost'; |
|
| 75 | 76 |
|
| 76 |
/**
|
|
| 77 |
* Sets the Subject of the message.
|
|
| 78 |
* @var string
|
|
| 79 |
*/
|
|
| 80 |
var $Subject = "";
|
|
| 77 |
/** |
|
| 78 |
* Sets the From name of the message.
|
|
| 79 |
* @var string |
|
| 80 |
*/ |
|
| 81 |
var $FromName = 'Root User';
|
|
| 81 | 82 |
|
| 82 |
/**
|
|
| 83 |
* Sets the Body of the message. This can be either an HTML or text body.
|
|
| 84 |
* If HTML then run IsHTML(true).
|
|
| 85 |
* @var string
|
|
| 86 |
*/
|
|
| 87 |
var $Body = "";
|
|
| 83 |
/** |
|
| 84 |
* Sets the Sender email (Return-Path) of the message. If not empty,
|
|
| 85 |
* will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
|
|
| 86 |
* @var string |
|
| 87 |
*/ |
|
| 88 |
var $Sender = '';
|
|
| 88 | 89 |
|
| 89 |
/** |
|
| 90 |
* Sets the text-only body of the message. This automatically sets the |
|
| 91 |
* email to multipart/alternative. This body can be read by mail |
|
| 92 |
* clients that do not have HTML email capability such as mutt. Clients |
|
| 93 |
* that can read HTML will view the normal Body. |
|
| 94 |
* @var string |
|
| 95 |
*/ |
|
| 96 |
var $AltBody = ""; |
|
| 90 |
/** |
|
| 91 |
* Sets the Subject of the message. |
|
| 92 |
* @var string |
|
| 93 |
*/ |
|
| 94 |
var $Subject = ''; |
|
| 97 | 95 |
|
| 98 |
/**
|
|
| 99 |
* Sets word wrapping on the body of the message to a given number of
|
|
| 100 |
* characters.
|
|
| 101 |
* @var int
|
|
| 102 |
*/
|
|
| 103 |
var $WordWrap = 0;
|
|
| 96 |
/** |
|
| 97 |
* Sets the Body of the message. This can be either an HTML or text body.
|
|
| 98 |
* If HTML then run IsHTML(true).
|
|
| 99 |
* @var string
|
|
| 100 |
*/ |
|
| 101 |
var $Body = '';
|
|
| 104 | 102 |
|
| 105 |
/** |
|
| 106 |
* Method to send mail: ("mail", "sendmail", or "smtp").
|
|
| 107 |
* @var string |
|
| 108 |
*/ |
|
| 109 |
var $Mailer = "mail"; |
|
| 103 |
/** |
|
| 104 |
* Sets the text-only body of the message. This automatically sets the |
|
| 105 |
* email to multipart/alternative. This body can be read by mail |
|
| 106 |
* clients that do not have HTML email capability such as mutt. Clients |
|
| 107 |
* that can read HTML will view the normal Body. |
|
| 108 |
* @var string |
|
| 109 |
*/ |
|
| 110 |
var $AltBody = ''; |
|
| 110 | 111 |
|
| 111 |
/** |
|
| 112 |
* Sets the path of the sendmail program. |
|
| 113 |
* @var string |
|
| 114 |
*/ |
|
| 115 |
var $Sendmail = "/usr/sbin/sendmail"; |
|
| 116 |
|
|
| 117 |
/** |
|
| 118 |
* Path to PHPMailer plugins. This is now only useful if the SMTP class |
|
| 119 |
* is in a different directory than the PHP include path. |
|
| 120 |
* @var string |
|
| 121 |
*/ |
|
| 122 |
var $PluginDir = ""; |
|
| 112 |
/** |
|
| 113 |
* Sets word wrapping on the body of the message to a given number of |
|
| 114 |
* characters. |
|
| 115 |
* @var int |
|
| 116 |
*/ |
|
| 117 |
var $WordWrap = 0; |
|
| 123 | 118 |
|
| 124 |
/**
|
|
| 125 |
* Holds PHPMailer version.
|
|
| 126 |
* @var string
|
|
| 127 |
*/
|
|
| 128 |
var $Version = "1.73";
|
|
| 119 |
/** |
|
| 120 |
* Method to send mail: ("mail", "sendmail", or "smtp").
|
|
| 121 |
* @var string
|
|
| 122 |
*/ |
|
| 123 |
var $Mailer = 'mail';
|
|
| 129 | 124 |
|
| 130 |
/**
|
|
| 131 |
* Sets the email address that a reading confirmation will be sent.
|
|
| 132 |
* @var string
|
|
| 133 |
*/
|
|
| 134 |
var $ConfirmReadingTo = "";
|
|
| 125 |
/** |
|
| 126 |
* Sets the path of the sendmail program.
|
|
| 127 |
* @var string |
|
| 128 |
*/ |
|
| 129 |
var $Sendmail = '/usr/sbin/sendmail';
|
|
| 135 | 130 |
|
| 136 |
/** |
|
| 137 |
* Sets the hostname to use in Message-Id and Received headers |
|
| 138 |
* and as default HELO string. If empty, the value returned |
|
| 139 |
* by SERVER_NAME is used or 'localhost.localdomain'. |
|
| 140 |
* @var string |
|
| 141 |
*/ |
|
| 142 |
var $Hostname = ""; |
|
| 131 |
/** |
|
| 132 |
* Path to PHPMailer plugins. This is now only useful if the SMTP class |
|
| 133 |
* is in a different directory than the PHP include path. |
|
| 134 |
* @var string |
|
| 135 |
*/ |
|
| 136 |
var $PluginDir = ''; |
|
| 143 | 137 |
|
| 144 |
///////////////////////////////////////////////// |
|
| 145 |
// SMTP VARIABLES |
|
| 146 |
///////////////////////////////////////////////// |
|
| 138 |
/** |
|
| 139 |
* Holds PHPMailer version. |
|
| 140 |
* @var string |
|
| 141 |
*/ |
|
| 142 |
var $Version = "2.0.0 rc3"; |
|
| 147 | 143 |
|
| 148 |
/** |
|
| 149 |
* Sets the SMTP hosts. All hosts must be separated by a |
|
| 150 |
* semicolon. You can also specify a different port |
|
| 151 |
* for each host by using this format: [hostname:port] |
|
| 152 |
* (e.g. "smtp1.example.com:25;smtp2.example.com"). |
|
| 153 |
* Hosts will be tried in order. |
|
| 154 |
* @var string |
|
| 155 |
*/ |
|
| 156 |
var $Host = "localhost"; |
|
| 144 |
/** |
|
| 145 |
* Sets the email address that a reading confirmation will be sent. |
|
| 146 |
* @var string |
|
| 147 |
*/ |
|
| 148 |
var $ConfirmReadingTo = ''; |
|
| 157 | 149 |
|
| 158 |
/** |
|
| 159 |
* Sets the default SMTP server port. |
|
| 160 |
* @var int |
|
| 161 |
*/ |
|
| 162 |
var $Port = 25; |
|
| 150 |
/** |
|
| 151 |
* Sets the hostname to use in Message-Id and Received headers |
|
| 152 |
* and as default HELO string. If empty, the value returned |
|
| 153 |
* by SERVER_NAME is used or 'localhost.localdomain'. |
|
| 154 |
* @var string |
|
| 155 |
*/ |
|
| 156 |
var $Hostname = ''; |
|
| 163 | 157 |
|
| 164 |
/** |
|
| 165 |
* Sets the SMTP HELO of the message (Default is $Hostname). |
|
| 166 |
* @var string |
|
| 167 |
*/ |
|
| 168 |
var $Helo = ""; |
|
| 158 |
///////////////////////////////////////////////// |
|
| 159 |
// PROPERTIES FOR SMTP |
|
| 160 |
///////////////////////////////////////////////// |
|
| 169 | 161 |
|
| 170 |
/** |
|
| 171 |
* Sets SMTP authentication. Utilizes the Username and Password variables. |
|
| 172 |
* @var bool |
|
| 173 |
*/ |
|
| 174 |
var $SMTPAuth = false; |
|
| 162 |
/** |
|
| 163 |
* Sets the SMTP hosts. All hosts must be separated by a |
|
| 164 |
* semicolon. You can also specify a different port |
|
| 165 |
* for each host by using this format: [hostname:port] |
|
| 166 |
* (e.g. "smtp1.example.com:25;smtp2.example.com"). |
|
| 167 |
* Hosts will be tried in order. |
|
| 168 |
* @var string |
|
| 169 |
*/ |
|
| 170 |
var $Host = 'localhost'; |
|
| 175 | 171 |
|
| 176 |
/**
|
|
| 177 |
* Sets SMTP username.
|
|
| 178 |
* @var string
|
|
| 179 |
*/
|
|
| 180 |
var $Username = "";
|
|
| 172 |
/** |
|
| 173 |
* Sets the default SMTP server port.
|
|
| 174 |
* @var int
|
|
| 175 |
*/ |
|
| 176 |
var $Port = 25;
|
|
| 181 | 177 |
|
| 182 |
/**
|
|
| 183 |
* Sets SMTP password.
|
|
| 184 |
* @var string
|
|
| 185 |
*/
|
|
| 186 |
var $Password = "";
|
|
| 178 |
/** |
|
| 179 |
* Sets the SMTP HELO of the message (Default is $Hostname).
|
|
| 180 |
* @var string
|
|
| 181 |
*/ |
|
| 182 |
var $Helo = '';
|
|
| 187 | 183 |
|
| 188 |
/**
|
|
| 189 |
* Sets the SMTP server timeout in seconds. This function will not
|
|
| 190 |
* work with the win32 version.
|
|
| 191 |
* @var int
|
|
| 192 |
*/
|
|
| 193 |
var $Timeout = 10;
|
|
| 184 |
/** |
|
| 185 |
* Sets connection prefix.
|
|
| 186 |
* Options are "", "ssl" or "tls"
|
|
| 187 |
* @var string
|
|
| 188 |
*/ |
|
| 189 |
var $SMTPSecure = "";
|
|
| 194 | 190 |
|
| 195 |
/**
|
|
| 196 |
* Sets SMTP class debugging on or off.
|
|
| 197 |
* @var bool
|
|
| 198 |
*/
|
|
| 199 |
var $SMTPDebug = false;
|
|
| 191 |
/** |
|
| 192 |
* Sets SMTP authentication. Utilizes the Username and Password variables.
|
|
| 193 |
* @var bool
|
|
| 194 |
*/ |
|
| 195 |
var $SMTPAuth = false;
|
|
| 200 | 196 |
|
| 201 |
/** |
|
| 202 |
* Prevents the SMTP connection from being closed after each mail |
|
| 203 |
* sending. If this is set to true then to close the connection |
|
| 204 |
* requires an explicit call to SmtpClose(). |
|
| 205 |
* @var bool |
|
| 206 |
*/ |
|
| 207 |
var $SMTPKeepAlive = false; |
|
| 197 |
/** |
|
| 198 |
* Sets SMTP username. |
|
| 199 |
* @var string |
|
| 200 |
*/ |
|
| 201 |
var $Username = ''; |
|
| 208 | 202 |
|
| 209 |
/**#@+ |
|
| 210 |
* @access private |
|
| 211 |
*/ |
|
| 212 |
var $smtp = NULL; |
|
| 213 |
var $to = array(); |
|
| 214 |
var $cc = array(); |
|
| 215 |
var $bcc = array(); |
|
| 216 |
var $ReplyTo = array(); |
|
| 217 |
var $attachment = array(); |
|
| 218 |
var $CustomHeader = array(); |
|
| 219 |
var $message_type = ""; |
|
| 220 |
var $boundary = array(); |
|
| 221 |
var $language = array(); |
|
| 222 |
var $error_count = 0; |
|
| 223 |
var $LE = "\n"; |
|
| 224 |
/**#@-*/ |
|
| 225 |
|
|
| 226 |
///////////////////////////////////////////////// |
|
| 227 |
// VARIABLE METHODS |
|
| 228 |
///////////////////////////////////////////////// |
|
| 203 |
/** |
|
| 204 |
* Sets SMTP password. |
|
| 205 |
* @var string |
|
| 206 |
*/ |
|
| 207 |
var $Password = ''; |
|
| 229 | 208 |
|
| 230 |
/** |
|
| 231 |
* Sets message type to HTML. |
|
| 232 |
* @param bool $bool |
|
| 233 |
* @return void |
|
| 234 |
*/ |
|
| 235 |
function IsHTML($bool) {
|
|
| 236 |
if($bool == true) |
|
| 237 |
$this->ContentType = "text/html"; |
|
| 238 |
else |
|
| 239 |
$this->ContentType = "text/plain"; |
|
| 240 |
} |
|
| 209 |
/** |
|
| 210 |
* Sets the SMTP server timeout in seconds. This function will not |
|
| 211 |
* work with the win32 version. |
|
| 212 |
* @var int |
|
| 213 |
*/ |
|
| 214 |
var $Timeout = 10; |
|
| 241 | 215 |
|
| 242 |
/** |
|
| 243 |
* Sets Mailer to send message using SMTP. |
|
| 244 |
* @return void |
|
| 245 |
*/ |
|
| 246 |
function IsSMTP() {
|
|
| 247 |
$this->Mailer = "smtp"; |
|
| 248 |
} |
|
| 216 |
/** |
|
| 217 |
* Sets SMTP class debugging on or off. |
|
| 218 |
* @var bool |
|
| 219 |
*/ |
|
| 220 |
var $SMTPDebug = false; |
|
| 249 | 221 |
|
| 250 |
/**
|
|
| 251 |
* Sets Mailer to send message using PHP mail() function.
|
|
| 252 |
* @return void
|
|
| 253 |
*/
|
|
| 254 |
function IsMail() {
|
|
| 255 |
$this->Mailer = "mail";
|
|
| 256 |
}
|
|
| 222 |
/** |
|
| 223 |
* Prevents the SMTP connection from being closed after each mail
|
|
| 224 |
* sending. If this is set to true then to close the connection
|
|
| 225 |
* requires an explicit call to SmtpClose().
|
|
| 226 |
* @var bool
|
|
| 227 |
*/
|
|
| 228 |
var $SMTPKeepAlive = false;
|
|
| 257 | 229 |
|
| 258 |
/** |
|
| 259 |
* Sets Mailer to send message using the $Sendmail program. |
|
| 260 |
* @return void |
|
| 261 |
*/ |
|
| 262 |
function IsSendmail() {
|
|
| 263 |
$this->Mailer = "sendmail"; |
|
| 264 |
} |
|
| 230 |
/** |
|
| 231 |
* Provides the ability to have the TO field process individual |
|
| 232 |
* emails, instead of sending to entire TO addresses |
|
| 233 |
* @var bool |
|
| 234 |
*/ |
|
| 235 |
var $SingleTo = false; |
|
| 265 | 236 |
|
| 266 |
/** |
|
| 267 |
* Sets Mailer to send message using the qmail MTA. |
|
| 268 |
* @return void |
|
| 269 |
*/ |
|
| 270 |
function IsQmail() {
|
|
| 271 |
$this->Sendmail = "/var/qmail/bin/sendmail"; |
|
| 272 |
$this->Mailer = "sendmail"; |
|
| 273 |
} |
|
| 237 |
///////////////////////////////////////////////// |
|
| 238 |
// PROPERTIES, PRIVATE |
|
| 239 |
///////////////////////////////////////////////// |
|
| 274 | 240 |
|
| 241 |
var $smtp = NULL; |
|
| 242 |
var $to = array(); |
|
| 243 |
var $cc = array(); |
|
| 244 |
var $bcc = array(); |
|
| 245 |
var $ReplyTo = array(); |
|
| 246 |
var $attachment = array(); |
|
| 247 |
var $CustomHeader = array(); |
|
| 248 |
var $message_type = ''; |
|
| 249 |
var $boundary = array(); |
|
| 250 |
var $language = array(); |
|
| 251 |
var $error_count = 0; |
|
| 252 |
var $LE = "\n"; |
|
| 275 | 253 |
|
| 276 |
/////////////////////////////////////////////////
|
|
| 277 |
// RECIPIENT METHODS
|
|
| 278 |
/////////////////////////////////////////////////
|
|
| 254 |
///////////////////////////////////////////////// |
|
| 255 |
// METHODS, VARIABLES
|
|
| 256 |
///////////////////////////////////////////////// |
|
| 279 | 257 |
|
| 280 |
/**
|
|
| 281 |
* Adds a "To" address.
|
|
| 282 |
* @param string $address
|
|
| 283 |
* @param string $name
|
|
| 284 |
* @return void
|
|
| 285 |
*/
|
|
| 286 |
function AddAddress($address, $name = "") {
|
|
| 287 |
$cur = count($this->to);
|
|
| 288 |
$this->to[$cur][0] = trim($address);
|
|
| 289 |
$this->to[$cur][1] = $name;
|
|
| 258 |
/** |
|
| 259 |
* Sets message type to HTML.
|
|
| 260 |
* @param bool $bool
|
|
| 261 |
* @return void
|
|
| 262 |
*/
|
|
| 263 |
function IsHTML($bool) {
|
|
| 264 |
if($bool == true) {
|
|
| 265 |
$this->ContentType = 'text/html';
|
|
| 266 |
} else {
|
|
| 267 |
$this->ContentType = 'text/plain';
|
|
| 290 | 268 |
} |
| 269 |
} |
|
| 291 | 270 |
|
| 292 |
/** |
|
| 293 |
* Adds a "Cc" address. Note: this function works |
|
| 294 |
* with the SMTP mailer on win32, not with the "mail" |
|
| 295 |
* mailer. |
|
| 296 |
* @param string $address |
|
| 297 |
* @param string $name |
|
| 298 |
* @return void |
|
| 299 |
*/ |
|
| 300 |
function AddCC($address, $name = "") {
|
|
| 301 |
$cur = count($this->cc); |
|
| 302 |
$this->cc[$cur][0] = trim($address); |
|
| 303 |
$this->cc[$cur][1] = $name; |
|
| 304 |
} |
|
| 271 |
/** |
|
| 272 |
* Sets Mailer to send message using SMTP. |
|
| 273 |
* @return void |
|
| 274 |
*/ |
|
| 275 |
function IsSMTP() {
|
|
| 276 |
$this->Mailer = 'smtp'; |
|
| 277 |
} |
|
| 305 | 278 |
|
| 306 |
/** |
|
| 307 |
* Adds a "Bcc" address. Note: this function works |
|
| 308 |
* with the SMTP mailer on win32, not with the "mail" |
|
| 309 |
* mailer. |
|
| 310 |
* @param string $address |
|
| 311 |
* @param string $name |
|
| 312 |
* @return void |
|
| 313 |
*/ |
|
| 314 |
function AddBCC($address, $name = "") {
|
|
| 315 |
$cur = count($this->bcc); |
|
| 316 |
$this->bcc[$cur][0] = trim($address); |
|
| 317 |
$this->bcc[$cur][1] = $name; |
|
| 318 |
} |
|
| 279 |
/** |
|
| 280 |
* Sets Mailer to send message using PHP mail() function. |
|
| 281 |
* @return void |
|
| 282 |
*/ |
|
| 283 |
function IsMail() {
|
|
| 284 |
$this->Mailer = 'mail'; |
|
| 285 |
} |
|
| 319 | 286 |
|
| 320 |
/** |
|
| 321 |
* Adds a "Reply-to" address. |
|
| 322 |
* @param string $address |
|
| 323 |
* @param string $name |
|
| 324 |
* @return void |
|
| 325 |
*/ |
|
| 326 |
function AddReplyTo($address, $name = "") {
|
|
| 327 |
$cur = count($this->ReplyTo); |
|
| 328 |
$this->ReplyTo[$cur][0] = trim($address); |
|
| 329 |
$this->ReplyTo[$cur][1] = $name; |
|
| 330 |
} |
|
| 287 |
/** |
|
| 288 |
* Sets Mailer to send message using the $Sendmail program. |
|
| 289 |
* @return void |
|
| 290 |
*/ |
|
| 291 |
function IsSendmail() {
|
|
| 292 |
$this->Mailer = 'sendmail'; |
|
| 293 |
} |
|
| 331 | 294 |
|
| 295 |
/** |
|
| 296 |
* Sets Mailer to send message using the qmail MTA. |
|
| 297 |
* @return void |
|
| 298 |
*/ |
|
| 299 |
function IsQmail() {
|
|
| 300 |
$this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 301 |
$this->Mailer = 'sendmail'; |
|
| 302 |
} |
|
| 332 | 303 |
|
| 333 |
/////////////////////////////////////////////////
|
|
| 334 |
// MAIL SENDING METHODS
|
|
| 335 |
/////////////////////////////////////////////////
|
|
| 304 |
///////////////////////////////////////////////// |
|
| 305 |
// METHODS, RECIPIENTS
|
|
| 306 |
///////////////////////////////////////////////// |
|
| 336 | 307 |
|
| 337 |
/** |
|
| 338 |
* Creates message and assigns Mailer. If the message is |
|
| 339 |
* not sent successfully then it returns false. Use the ErrorInfo |
|
| 340 |
* variable to view description of the error. |
|
| 341 |
* @return bool |
|
| 342 |
*/ |
|
| 343 |
function Send() {
|
|
| 344 |
$header = ""; |
|
| 345 |
$body = ""; |
|
| 346 |
$result = true; |
|
| 308 |
/** |
|
| 309 |
* Adds a "To" address. |
|
| 310 |
* @param string $address |
|
| 311 |
* @param string $name |
|
| 312 |
* @return void |
|
| 313 |
*/ |
|
| 314 |
function AddAddress($address, $name = '') {
|
|
| 315 |
$cur = count($this->to); |
|
| 316 |
$this->to[$cur][0] = trim($address); |
|
| 317 |
$this->to[$cur][1] = $name; |
|
| 318 |
} |
|
| 347 | 319 |
|
| 348 |
if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) |
|
| 349 |
{
|
|
| 350 |
$this->SetError($this->Lang("provide_address"));
|
|
| 351 |
return false; |
|
| 352 |
} |
|
| 320 |
/** |
|
| 321 |
* Adds a "Cc" address. Note: this function works |
|
| 322 |
* with the SMTP mailer on win32, not with the "mail" |
|
| 323 |
* mailer. |
|
| 324 |
* @param string $address |
|
| 325 |
* @param string $name |
|
| 326 |
* @return void |
|
| 327 |
*/ |
|
| 328 |
function AddCC($address, $name = '') {
|
|
| 329 |
$cur = count($this->cc); |
|
| 330 |
$this->cc[$cur][0] = trim($address); |
|
| 331 |
$this->cc[$cur][1] = $name; |
|
| 332 |
} |
|
| 353 | 333 |
|
| 354 |
// Set whether the message is multipart/alternative |
|
| 355 |
if(!empty($this->AltBody)) |
|
| 356 |
$this->ContentType = "multipart/alternative"; |
|
| 334 |
/** |
|
| 335 |
* Adds a "Bcc" address. Note: this function works |
|
| 336 |
* with the SMTP mailer on win32, not with the "mail" |
|
| 337 |
* mailer. |
|
| 338 |
* @param string $address |
|
| 339 |
* @param string $name |
|
| 340 |
* @return void |
|
| 341 |
*/ |
|
| 342 |
function AddBCC($address, $name = '') {
|
|
| 343 |
$cur = count($this->bcc); |
|
| 344 |
$this->bcc[$cur][0] = trim($address); |
|
| 345 |
$this->bcc[$cur][1] = $name; |
|
| 346 |
} |
|
| 357 | 347 |
|
| 358 |
$this->error_count = 0; // reset errors |
|
| 359 |
$this->SetMessageType(); |
|
| 360 |
$header .= $this->CreateHeader(); |
|
| 361 |
$body = $this->CreateBody(); |
|
| 348 |
/** |
|
| 349 |
* Adds a "Reply-To" address. |
|
| 350 |
* @param string $address |
|
| 351 |
* @param string $name |
|
| 352 |
* @return void |
|
| 353 |
*/ |
|
| 354 |
function AddReplyTo($address, $name = '') {
|
|
| 355 |
$cur = count($this->ReplyTo); |
|
| 356 |
$this->ReplyTo[$cur][0] = trim($address); |
|
| 357 |
$this->ReplyTo[$cur][1] = $name; |
|
| 358 |
} |
|
| 362 | 359 |
|
| 363 |
if($body == "") { return false; }
|
|
| 360 |
///////////////////////////////////////////////// |
|
| 361 |
// METHODS, MAIL SENDING |
|
| 362 |
///////////////////////////////////////////////// |
|
| 364 | 363 |
|
| 365 |
// Choose the mailer |
|
| 366 |
switch($this->Mailer) |
|
| 367 |
{
|
|
| 368 |
case "sendmail": |
|
| 369 |
$result = $this->SendmailSend($header, $body); |
|
| 370 |
break; |
|
| 371 |
case "mail": |
|
| 372 |
$result = $this->MailSend($header, $body); |
|
| 373 |
break; |
|
| 374 |
case "smtp": |
|
| 375 |
$result = $this->SmtpSend($header, $body); |
|
| 376 |
break; |
|
| 377 |
default: |
|
| 378 |
$this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
|
|
| 379 |
$result = false; |
|
| 380 |
break; |
|
| 381 |
} |
|
| 364 |
/** |
|
| 365 |
* Creates message and assigns Mailer. If the message is |
|
| 366 |
* not sent successfully then it returns false. Use the ErrorInfo |
|
| 367 |
* variable to view description of the error. |
|
| 368 |
* @return bool |
|
| 369 |
*/ |
|
| 370 |
function Send() {
|
|
| 371 |
$header = ''; |
|
| 372 |
$body = ''; |
|
| 373 |
$result = true; |
|
| 382 | 374 |
|
| 383 |
return $result; |
|
| 375 |
if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
|
|
| 376 |
$this->SetError($this->Lang('provide_address'));
|
|
| 377 |
return false; |
|
| 384 | 378 |
} |
| 385 |
|
|
| 386 |
/** |
|
| 387 |
* Sends mail using the $Sendmail program. |
|
| 388 |
* @access private |
|
| 389 |
* @return bool |
|
| 390 |
*/ |
|
| 391 |
function SendmailSend($header, $body) {
|
|
| 392 |
if ($this->Sender != "") |
|
| 393 |
$sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender);
|
|
| 394 |
else |
|
| 395 |
$sendmail = sprintf("%s -oi -t", $this->Sendmail);
|
|
| 396 | 379 |
|
| 397 |
if(!@$mail = popen($sendmail, "w")) |
|
| 398 |
{
|
|
| 399 |
$this->SetError($this->Lang("execute") . $this->Sendmail);
|
|
| 400 |
return false; |
|
| 401 |
} |
|
| 380 |
/* Set whether the message is multipart/alternative */ |
|
| 381 |
if(!empty($this->AltBody)) {
|
|
| 382 |
$this->ContentType = 'multipart/alternative'; |
|
| 383 |
} |
|
| 402 | 384 |
|
| 403 |
fputs($mail, $header); |
|
| 404 |
fputs($mail, $body); |
|
| 405 |
|
|
| 406 |
$result = pclose($mail) >> 8 & 0xFF; |
|
| 407 |
if($result != 0) |
|
| 408 |
{
|
|
| 409 |
$this->SetError($this->Lang("execute") . $this->Sendmail);
|
|
| 410 |
return false; |
|
| 411 |
} |
|
| 385 |
$this->error_count = 0; // reset errors |
|
| 386 |
$this->SetMessageType(); |
|
| 387 |
$header .= $this->CreateHeader(); |
|
| 388 |
$body = $this->CreateBody(); |
|
| 412 | 389 |
|
| 413 |
return true; |
|
| 390 |
if($body == '') {
|
|
| 391 |
return false; |
|
| 414 | 392 |
} |
| 415 | 393 |
|
| 416 |
/** |
|
| 417 |
* Sends mail using the PHP mail() function. |
|
| 418 |
* @access private |
|
| 419 |
* @return bool |
|
| 420 |
*/ |
|
| 421 |
function MailSend($header, $body) {
|
|
| 422 |
$to = ""; |
|
| 423 |
for($i = 0; $i < count($this->to); $i++) |
|
| 424 |
{
|
|
| 425 |
if($i != 0) { $to .= ", "; }
|
|
| 426 |
$to .= $this->to[$i][0]; |
|
| 427 |
} |
|
| 394 |
/* Choose the mailer */ |
|
| 395 |
switch($this->Mailer) {
|
|
| 396 |
case 'sendmail': |
|
| 397 |
$result = $this->SendmailSend($header, $body); |
|
| 398 |
break; |
|
| 399 |
case 'smtp': |
|
| 400 |
$result = $this->SmtpSend($header, $body); |
|
| 401 |
break; |
|
| 402 |
case 'mail': |
|
| 403 |
$result = $this->MailSend($header, $body); |
|
| 404 |
break; |
|
| 405 |
default: |
|
| 406 |
$result = $this->MailSend($header, $body); |
|
| 407 |
break; |
|
| 408 |
//$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
|
|
| 409 |
//$result = false; |
|
| 410 |
//break; |
|
| 411 |
} |
|
| 428 | 412 |
|
| 429 |
if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
|
|
| 430 |
{
|
|
| 431 |
$old_from = ini_get("sendmail_from");
|
|
| 432 |
ini_set("sendmail_from", $this->Sender);
|
|
| 433 |
$params = sprintf("-oi -f %s", $this->Sender);
|
|
| 434 |
$rt = @mail($to, $this->EncodeHeader($this->Subject), $body, |
|
| 435 |
$header, $params); |
|
| 436 |
} |
|
| 437 |
else |
|
| 438 |
$rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header); |
|
| 413 |
return $result; |
|
| 414 |
} |
|
| 439 | 415 |
|
| 440 |
if (isset($old_from)) |
|
| 441 |
ini_set("sendmail_from", $old_from);
|
|
| 416 |
/** |
|
| 417 |
* Sends mail using the $Sendmail program. |
|
| 418 |
* @access private |
|
| 419 |
* @return bool |
|
| 420 |
*/ |
|
| 421 |
function SendmailSend($header, $body) {
|
|
| 422 |
if ($this->Sender != '') {
|
|
| 423 |
$sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
|
|
| 424 |
} else {
|
|
| 425 |
$sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
|
|
| 426 |
} |
|
| 442 | 427 |
|
| 443 |
if(!$rt) |
|
| 444 |
{
|
|
| 445 |
$this->SetError($this->Lang("instantiate"));
|
|
| 446 |
return false; |
|
| 447 |
} |
|
| 428 |
if(!@$mail = popen($sendmail, 'w')) {
|
|
| 429 |
$this->SetError($this->Lang('execute') . $this->Sendmail);
|
|
| 430 |
return false; |
|
| 431 |
} |
|
| 448 | 432 |
|
| 449 |
return true; |
|
| 433 |
fputs($mail, $header); |
|
| 434 |
fputs($mail, $body); |
|
| 435 |
|
|
| 436 |
$result = pclose($mail) >> 8 & 0xFF; |
|
| 437 |
if($result != 0) {
|
|
| 438 |
$this->SetError($this->Lang('execute') . $this->Sendmail);
|
|
| 439 |
return false; |
|
| 450 | 440 |
} |
| 451 | 441 |
|
| 452 |
/** |
|
| 453 |
* Sends mail via SMTP using PhpSMTP (Author: |
|
| 454 |
* Chris Ryan). Returns bool. Returns false if there is a |
|
| 455 |
* bad MAIL FROM, RCPT, or DATA input. |
|
| 456 |
* @access private |
|
| 457 |
* @return bool |
|
| 458 |
*/ |
|
| 459 |
function SmtpSend($header, $body) {
|
|
| 460 |
include_once($this->PluginDir . "class.smtp.php"); |
|
| 461 |
$error = ""; |
|
| 462 |
$bad_rcpt = array(); |
|
| 442 |
return true; |
|
| 443 |
} |
|
| 463 | 444 |
|
| 464 |
if(!$this->SmtpConnect()) |
|
| 465 |
return false; |
|
| 445 |
/** |
|
| 446 |
* Sends mail using the PHP mail() function. |
|
| 447 |
* @access private |
|
| 448 |
* @return bool |
|
| 449 |
*/ |
|
| 450 |
function MailSend($header, $body) {
|
|
| 466 | 451 |
|
| 467 |
$smtp_from = ($this->Sender == "") ? $this->From : $this->Sender; |
|
| 468 |
if(!$this->smtp->Mail($smtp_from)) |
|
| 469 |
{
|
|
| 470 |
$error = $this->Lang("from_failed") . $smtp_from;
|
|
| 471 |
$this->SetError($error); |
|
| 472 |
$this->smtp->Reset(); |
|
| 473 |
return false; |
|
| 474 |
} |
|
| 452 |
$to = ''; |
|
| 453 |
for($i = 0; $i < count($this->to); $i++) {
|
|
| 454 |
if($i != 0) { $to .= ', '; }
|
|
| 455 |
$to .= $this->AddrFormat($this->to[$i]); |
|
| 456 |
} |
|
| 475 | 457 |
|
| 476 |
// Attempt to send attach all recipients |
|
| 477 |
for($i = 0; $i < count($this->to); $i++) |
|
| 478 |
{
|
|
| 479 |
if(!$this->smtp->Recipient($this->to[$i][0])) |
|
| 480 |
$bad_rcpt[] = $this->to[$i][0]; |
|
| 481 |
} |
|
| 482 |
for($i = 0; $i < count($this->cc); $i++) |
|
| 483 |
{
|
|
| 484 |
if(!$this->smtp->Recipient($this->cc[$i][0])) |
|
| 485 |
$bad_rcpt[] = $this->cc[$i][0]; |
|
| 486 |
} |
|
| 487 |
for($i = 0; $i < count($this->bcc); $i++) |
|
| 488 |
{
|
|
| 489 |
if(!$this->smtp->Recipient($this->bcc[$i][0])) |
|
| 490 |
$bad_rcpt[] = $this->bcc[$i][0]; |
|
| 491 |
} |
|
| 458 |
$toArr = split(',', $to);
|
|
| 492 | 459 |
|
| 493 |
if(count($bad_rcpt) > 0) // Create error message |
|
| 494 |
{
|
|
| 495 |
for($i = 0; $i < count($bad_rcpt); $i++) |
|
| 496 |
{
|
|
| 497 |
if($i != 0) { $error .= ", "; }
|
|
| 498 |
$error .= $bad_rcpt[$i]; |
|
| 499 |
} |
|
| 500 |
$error = $this->Lang("recipients_failed") . $error;
|
|
| 501 |
$this->SetError($error); |
|
| 502 |
$this->smtp->Reset(); |
|
| 503 |
return false; |
|
| 460 |
if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
|
|
| 461 |
$old_from = ini_get('sendmail_from');
|
|
| 462 |
ini_set('sendmail_from', $this->Sender);
|
|
| 463 |
$params = sprintf("-oi -f %s", $this->Sender);
|
|
| 464 |
if ($this->SingleTo === true && count($toArr) > 1) {
|
|
| 465 |
foreach ($toArr as $key => $val) {
|
|
| 466 |
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 504 | 467 |
} |
| 505 |
|
|
| 506 |
if(!$this->smtp->Data($header . $body)) |
|
| 507 |
{
|
|
| 508 |
$this->SetError($this->Lang("data_not_accepted"));
|
|
| 509 |
$this->smtp->Reset(); |
|
| 510 |
return false; |
|
| 468 |
} else {
|
|
| 469 |
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 470 |
} |
|
| 471 |
} else {
|
|
| 472 |
if ($this->SingleTo === true && count($toArr) > 1) {
|
|
| 473 |
foreach ($toArr as $key => $val) {
|
|
| 474 |
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 511 | 475 |
} |
| 512 |
if($this->SMTPKeepAlive == true)
|
|
| 513 |
$this->smtp->Reset();
|
|
| 514 |
else
|
|
| 515 |
$this->SmtpClose();
|
|
| 476 |
} else {
|
|
| 477 |
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
|
|
| 478 |
}
|
|
| 479 |
}
|
|
| 516 | 480 |
|
| 517 |
return true; |
|
| 481 |
if (isset($old_from)) {
|
|
| 482 |
ini_set('sendmail_from', $old_from);
|
|
| 518 | 483 |
} |
| 519 | 484 |
|
| 520 |
/** |
|
| 521 |
* Initiates a connection to an SMTP server. Returns false if the |
|
| 522 |
* operation failed. |
|
| 523 |
* @access private |
|
| 524 |
* @return bool |
|
| 525 |
*/ |
|
| 526 |
function SmtpConnect() {
|
|
| 527 |
if($this->smtp == NULL) { $this->smtp = new SMTP(); }
|
|
| 485 |
if(!$rt) {
|
|
| 486 |
$this->SetError($this->Lang('instantiate'));
|
|
| 487 |
return false; |
|
| 488 |
} |
|
| 528 | 489 |
|
| 529 |
$this->smtp->do_debug = $this->SMTPDebug; |
|
| 530 |
$hosts = explode(";", $this->Host);
|
|
| 531 |
$index = 0; |
|
| 532 |
$connection = ($this->smtp->Connected()); |
|
| 490 |
return true; |
|
| 491 |
} |
|
| 533 | 492 |
|
| 534 |
// Retry while there is no connection |
|
| 535 |
while($index < count($hosts) && $connection == false) |
|
| 536 |
{
|
|
| 537 |
if(strstr($hosts[$index], ":")) |
|
| 538 |
list($host, $port) = explode(":", $hosts[$index]);
|
|
| 539 |
else |
|
| 540 |
{
|
|
| 541 |
$host = $hosts[$index]; |
|
| 542 |
$port = $this->Port; |
|
| 543 |
} |
|
| 493 |
/** |
|
| 494 |
* Sends mail via SMTP using PhpSMTP (Author: |
|
| 495 |
* Chris Ryan). Returns bool. Returns false if there is a |
|
| 496 |
* bad MAIL FROM, RCPT, or DATA input. |
|
| 497 |
* @access private |
|
| 498 |
* @return bool |
|
| 499 |
*/ |
|
| 500 |
function SmtpSend($header, $body) {
|
|
| 501 |
include_once($this->PluginDir . 'class.smtp.php'); |
|
| 502 |
$error = ''; |
|
| 503 |
$bad_rcpt = array(); |
|
| 544 | 504 |
|
| 545 |
if($this->smtp->Connect($host, $port, $this->Timeout)) |
|
| 546 |
{
|
|
| 547 |
if ($this->Helo != '') |
|
| 548 |
$this->smtp->Hello($this->Helo); |
|
| 549 |
else |
|
| 550 |
$this->smtp->Hello($this->ServerHostname()); |
|
| 551 |
|
|
| 552 |
if($this->SMTPAuth) |
|
| 553 |
{
|
|
| 554 |
if(!$this->smtp->Authenticate($this->Username, |
|
| 555 |
$this->Password)) |
|
| 556 |
{
|
|
| 557 |
$this->SetError($this->Lang("authenticate"));
|
|
| 558 |
$this->smtp->Reset(); |
|
| 559 |
$connection = false; |
|
| 560 |
} |
|
| 561 |
} |
|
| 562 |
$connection = true; |
|
| 563 |
} |
|
| 564 |
$index++; |
|
| 565 |
} |
|
| 566 |
if(!$connection) |
|
| 567 |
$this->SetError($this->Lang("connect_host"));
|
|
| 505 |
if(!$this->SmtpConnect()) {
|
|
| 506 |
return false; |
|
| 507 |
} |
|
| 568 | 508 |
|
| 569 |
return $connection; |
|
| 509 |
$smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
|
| 510 |
if(!$this->smtp->Mail($smtp_from)) {
|
|
| 511 |
$error = $this->Lang('from_failed') . $smtp_from;
|
|
| 512 |
$this->SetError($error); |
|
| 513 |
$this->smtp->Reset(); |
|
| 514 |
return false; |
|
| 570 | 515 |
} |
| 571 | 516 |
|
| 572 |
/** |
|
| 573 |
* Closes the active SMTP session if one exists. |
|
| 574 |
* @return void |
|
| 575 |
*/ |
|
| 576 |
function SmtpClose() {
|
|
| 577 |
if($this->smtp != NULL) |
|
| 578 |
{
|
|
| 579 |
if($this->smtp->Connected()) |
|
| 580 |
{
|
|
| 581 |
$this->smtp->Quit(); |
|
| 582 |
$this->smtp->Close(); |
|
| 583 |
} |
|
| 584 |
} |
|
| 517 |
/* Attempt to send attach all recipients */ |
|
| 518 |
for($i = 0; $i < count($this->to); $i++) {
|
|
| 519 |
if(!$this->smtp->Recipient($this->to[$i][0])) {
|
|
| 520 |
$bad_rcpt[] = $this->to[$i][0]; |
|
| 521 |
} |
|
| 585 | 522 |
} |
| 523 |
for($i = 0; $i < count($this->cc); $i++) {
|
|
| 524 |
if(!$this->smtp->Recipient($this->cc[$i][0])) {
|
|
| 525 |
$bad_rcpt[] = $this->cc[$i][0]; |
|
| 526 |
} |
|
| 527 |
} |
|
| 528 |
for($i = 0; $i < count($this->bcc); $i++) {
|
|
| 529 |
if(!$this->smtp->Recipient($this->bcc[$i][0])) {
|
|
| 530 |
$bad_rcpt[] = $this->bcc[$i][0]; |
|
| 531 |
} |
|
| 532 |
} |
|
| 586 | 533 |
|
| 587 |
/** |
|
| 588 |
* Sets the language for all class error messages. Returns false |
|
| 589 |
* if it cannot load the language file. The default language type |
|
| 590 |
* is English. |
|
| 591 |
* @param string $lang_type Type of language (e.g. Portuguese: "br") |
|
| 592 |
* @param string $lang_path Path to the language file directory |
|
| 593 |
* @access public |
|
| 594 |
* @return bool |
|
| 595 |
*/ |
|
| 596 |
function SetLanguage($lang_type, $lang_path = "language/") {
|
|
| 597 |
if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) |
|
| 598 |
include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); |
|
| 599 |
else if(file_exists($lang_path.'phpmailer.lang-en.php')) |
|
| 600 |
include($lang_path.'phpmailer.lang-en.php'); |
|
| 601 |
else |
|
| 602 |
{
|
|
| 603 |
$this->SetError("Could not load language file");
|
|
| 604 |
return false; |
|
| 534 |
if(count($bad_rcpt) > 0) { // Create error message
|
|
| 535 |
for($i = 0; $i < count($bad_rcpt); $i++) {
|
|
| 536 |
if($i != 0) {
|
|
| 537 |
$error .= ', '; |
|
| 605 | 538 |
} |
| 606 |
$this->language = $PHPMAILER_LANG; |
|
| 607 |
|
|
| 608 |
return true; |
|
| 539 |
$error .= $bad_rcpt[$i]; |
|
| 540 |
} |
|
| 541 |
$error = $this->Lang('recipients_failed') . $error;
|
|
| 542 |
$this->SetError($error); |
|
| 543 |
$this->smtp->Reset(); |
|
| 544 |
return false; |
|
| 609 | 545 |
} |
| 610 | 546 |
|
| 611 |
///////////////////////////////////////////////// |
|
| 612 |
// MESSAGE CREATION METHODS |
|
| 613 |
///////////////////////////////////////////////// |
|
| 547 |
if(!$this->smtp->Data($header . $body)) {
|
|
| 548 |
$this->SetError($this->Lang('data_not_accepted'));
|
|
| 549 |
$this->smtp->Reset(); |
|
| 550 |
return false; |
|
| 551 |
} |
|
| 552 |
if($this->SMTPKeepAlive == true) {
|
|
| 553 |
$this->smtp->Reset(); |
|
| 554 |
} else {
|
|
| 555 |
$this->SmtpClose(); |
|
| 556 |
} |
|
| 614 | 557 |
|
| 615 |
/** |
|
| 616 |
* Creates recipient headers. |
|
| 617 |
* @access private |
|
| 618 |
* @return string |
|
| 619 |
*/ |
|
| 620 |
function AddrAppend($type, $addr) {
|
|
| 621 |
$addr_str = $type . ": "; |
|
| 622 |
$addr_str .= $this->AddrFormat($addr[0]); |
|
| 623 |
if(count($addr) > 1) |
|
| 624 |
{
|
|
| 625 |
for($i = 1; $i < count($addr); $i++) |
|
| 626 |
$addr_str .= ", " . $this->AddrFormat($addr[$i]); |
|
| 627 |
} |
|
| 628 |
$addr_str .= $this->LE; |
|
| 558 |
return true; |
|
| 559 |
} |
|
| 629 | 560 |
|
| 630 |
return $addr_str; |
|
| 561 |
/** |
|
| 562 |
* Initiates a connection to an SMTP server. Returns false if the |
|
| 563 |
* operation failed. |
|
| 564 |
* @access private |
|
| 565 |
* @return bool |
|
| 566 |
*/ |
|
| 567 |
function SmtpConnect() {
|
|
| 568 |
if($this->smtp == NULL) {
|
|
| 569 |
$this->smtp = new SMTP(); |
|
| 631 | 570 |
} |
| 632 |
|
|
| 633 |
/** |
|
| 634 |
* Formats an address correctly. |
|
| 635 |
* @access private |
|
| 636 |
* @return string |
|
| 637 |
*/ |
|
| 638 |
function AddrFormat($addr) {
|
|
| 639 |
if(empty($addr[1])) |
|
| 640 |
$formatted = $addr[0]; |
|
| 641 |
else |
|
| 642 |
{
|
|
| 643 |
$formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . |
|
| 644 |
$addr[0] . ">"; |
|
| 571 |
|
|
| 572 |
$this->smtp->do_debug = $this->SMTPDebug; |
|
| 573 |
$hosts = explode(';', $this->Host);
|
|
| 574 |
$index = 0; |
|
| 575 |
$connection = ($this->smtp->Connected()); |
|
| 576 |
|
|
| 577 |
/* Retry while there is no connection */ |
|
| 578 |
while($index < count($hosts) && $connection == false) {
|
|
| 579 |
$hostinfo = array(); |
|
| 580 |
if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
|
|
| 581 |
$host = $hostinfo[1]; |
|
| 582 |
$port = $hostinfo[2]; |
|
| 583 |
} else {
|
|
| 584 |
$host = $hosts[$index]; |
|
| 585 |
$port = $this->Port; |
|
| 586 |
} |
|
| 587 |
|
|
| 588 |
if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
|
|
| 589 |
if ($this->Helo != '') {
|
|
| 590 |
$this->smtp->Hello($this->Helo); |
|
| 591 |
} else {
|
|
| 592 |
$this->smtp->Hello($this->ServerHostname()); |
|
| 645 | 593 |
} |
| 646 | 594 |
|
| 647 |
return $formatted; |
|
| 595 |
$connection = true; |
|
| 596 |
if($this->SMTPAuth) {
|
|
| 597 |
if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
|
|
| 598 |
$this->SetError($this->Lang('authenticate'));
|
|
| 599 |
$this->smtp->Reset(); |
|
| 600 |
$connection = false; |
|
| 601 |
} |
|
| 602 |
} |
|
| 603 |
} |
|
| 604 |
$index++; |
|
| 648 | 605 |
} |
| 606 |
if(!$connection) {
|
|
| 607 |
$this->SetError($this->Lang('connect_host'));
|
|
| 608 |
} |
|
| 649 | 609 |
|
| 650 |
/** |
|
| 651 |
* Wraps message for use with mailers that do not |
|
| 652 |
* automatically perform wrapping and for quoted-printable. |
|
| 653 |
* Original written by philippe. |
|
| 654 |
* @access private |
|
| 655 |
* @return string |
|
| 656 |
*/ |
|
| 657 |
function WrapText($message, $length, $qp_mode = false) {
|
|
| 658 |
$soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
|
|
| 610 |
return $connection; |
|
| 611 |
} |
|
| 659 | 612 |
|
| 660 |
$message = $this->FixEOL($message); |
|
| 661 |
if (substr($message, -1) == $this->LE) |
|
| 662 |
$message = substr($message, 0, -1); |
|
| 613 |
/** |
|
| 614 |
* Closes the active SMTP session if one exists. |
|
| 615 |
* @return void |
|
| 616 |
*/ |
|
| 617 |
function SmtpClose() {
|
|
| 618 |
if($this->smtp != NULL) {
|
|
| 619 |
if($this->smtp->Connected()) {
|
|
| 620 |
$this->smtp->Quit(); |
|
| 621 |
$this->smtp->Close(); |
|
| 622 |
} |
|
| 623 |
} |
|
| 624 |
} |
|
| 663 | 625 |
|
| 664 |
$line = explode($this->LE, $message); |
|
| 665 |
$message = ""; |
|
| 666 |
for ($i=0 ;$i < count($line); $i++) |
|
| 667 |
{
|
|
| 668 |
$line_part = explode(" ", $line[$i]);
|
|
| 669 |
$buf = ""; |
|
| 670 |
for ($e = 0; $e<count($line_part); $e++) |
|
| 671 |
{
|
|
| 672 |
$word = $line_part[$e]; |
|
| 673 |
if ($qp_mode and (strlen($word) > $length)) |
|
| 674 |
{
|
|
| 675 |
$space_left = $length - strlen($buf) - 1; |
|
| 676 |
if ($e != 0) |
|
| 677 |
{
|
|
| 678 |
if ($space_left > 20) |
|
| 679 |
{
|
|
| 680 |
$len = $space_left; |
|
| 681 |
if (substr($word, $len - 1, 1) == "=") |
|
| 682 |
$len--; |
|
| 683 |
elseif (substr($word, $len - 2, 1) == "=") |
|
| 684 |
$len -= 2; |
|
| 685 |
$part = substr($word, 0, $len); |
|
| 686 |
$word = substr($word, $len); |
|
| 687 |
$buf .= " " . $part; |
|
| 688 |
$message .= $buf . sprintf("=%s", $this->LE);
|
|
| 689 |
} |
|
| 690 |
else |
|
| 691 |
{
|
|
| 692 |
$message .= $buf . $soft_break; |
|
| 693 |
} |
|
| 694 |
$buf = ""; |
|
| 695 |
} |
|
| 696 |
while (strlen($word) > 0) |
|
| 697 |
{
|
|
| 698 |
$len = $length; |
|
| 699 |
if (substr($word, $len - 1, 1) == "=") |
|
| 700 |
$len--; |
|
| 701 |
elseif (substr($word, $len - 2, 1) == "=") |
|
| 702 |
$len -= 2; |
|
| 703 |
$part = substr($word, 0, $len); |
|
| 704 |
$word = substr($word, $len); |
|
| 626 |
/** |
|
| 627 |
* Sets the language for all class error messages. Returns false |
|
| 628 |
* if it cannot load the language file. The default language type |
|
| 629 |
* is English. |
|
| 630 |
* @param string $lang_type Type of language (e.g. Portuguese: "br") |
|
| 631 |
* @param string $lang_path Path to the language file directory |
|
| 632 |
* @access public |
|
| 633 |
* @return bool |
|
| 634 |
*/ |
|
| 635 |
function SetLanguage($lang_type, $lang_path = 'language/') {
|
|
| 636 |
if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
|
|
| 637 |
include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); |
|
| 638 |
} elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
|
|
| 639 |
include($lang_path.'phpmailer.lang-en.php'); |
|
| 640 |
} else {
|
|
| 641 |
$this->SetError('Could not load language file');
|
|
| 642 |
return false; |
|
| 643 |
} |
|
| 644 |
$this->language = $PHPMAILER_LANG; |
|
| 705 | 645 |
|
| 706 |
if (strlen($word) > 0) |
|
| 707 |
$message .= $part . sprintf("=%s", $this->LE);
|
|
| 708 |
else |
|
| 709 |
$buf = $part; |
|
| 710 |
} |
|
| 711 |
} |
|
| 712 |
else |
|
| 713 |
{
|
|
| 714 |
$buf_o = $buf; |
|
| 715 |
$buf .= ($e == 0) ? $word : (" " . $word);
|
|
| 646 |
return true; |
|
| 647 |
} |
|
| 716 | 648 |
|
| 717 |
if (strlen($buf) > $length and $buf_o != "") |
|
| 718 |
{
|
|
| 719 |
$message .= $buf_o . $soft_break; |
|
| 720 |
$buf = $word; |
|
| 721 |
} |
|
| 722 |
} |
|
| 723 |
} |
|
| 724 |
$message .= $buf . $this->LE; |
|
| 725 |
} |
|
| 649 |
///////////////////////////////////////////////// |
|
| 650 |
// METHODS, MESSAGE CREATION |
|
| 651 |
///////////////////////////////////////////////// |
|
| 726 | 652 |
|
| 727 |
return $message; |
|
| 653 |
/** |
|
| 654 |
* Creates recipient headers. |
|
| 655 |
* @access private |
|
| 656 |
* @return string |
|
| 657 |
*/ |
|
| 658 |
function AddrAppend($type, $addr) {
|
|
| 659 |
$addr_str = $type . ': '; |
|
| 660 |
$addr_str .= $this->AddrFormat($addr[0]); |
|
| 661 |
if(count($addr) > 1) {
|
|
| 662 |
for($i = 1; $i < count($addr); $i++) {
|
|
| 663 |
$addr_str .= ', ' . $this->AddrFormat($addr[$i]); |
|
| 664 |
} |
|
| 728 | 665 |
} |
| 729 |
|
|
| 730 |
/** |
|
| 731 |
* Set the body wrapping. |
|
| 732 |
* @access private |
|
| 733 |
* @return void |
|
| 734 |
*/ |
|
| 735 |
function SetWordWrap() {
|
|
| 736 |
if($this->WordWrap < 1) |
|
| 737 |
return; |
|
| 738 |
|
|
| 739 |
switch($this->message_type) |
|
| 740 |
{
|
|
| 741 |
case "alt": |
|
| 742 |
// fall through |
|
| 743 |
case "alt_attachments": |
|
| 744 |
$this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|
| 745 |
break; |
|
| 746 |
default: |
|
| 747 |
$this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|
| 748 |
break; |
|
| 749 |
} |
|
| 750 |
} |
|
| 666 |
$addr_str .= $this->LE; |
|
| 751 | 667 |
|
| 752 |
/** |
|
| 753 |
* Assembles message header. |
|
| 754 |
* @access private |
|
| 755 |
* @return string |
|
| 756 |
*/ |
|
| 757 |
function CreateHeader() {
|
|
| 758 |
$result = ""; |
|
| 759 |
|
|
| 760 |
// Set the boundaries |
|
| 761 |
$uniq_id = md5(uniqid(time())); |
|
| 762 |
$this->boundary[1] = "b1_" . $uniq_id; |
|
| 763 |
$this->boundary[2] = "b2_" . $uniq_id; |
|
| 668 |
return $addr_str; |
|
| 669 |
} |
|
| 764 | 670 |
|
| 765 |
$result .= $this->HeaderLine("Date", $this->RFCDate());
|
|
| 766 |
if($this->Sender == "") |
|
| 767 |
$result .= $this->HeaderLine("Return-Path", trim($this->From));
|
|
| 768 |
else |
|
| 769 |
$result .= $this->HeaderLine("Return-Path", trim($this->Sender));
|
|
| 770 |
|
|
| 771 |
// To be created automatically by mail() |
|
| 772 |
if($this->Mailer != "mail") |
|
| 773 |
{
|
|
| 774 |
if(count($this->to) > 0) |
|
| 775 |
$result .= $this->AddrAppend("To", $this->to);
|
|
| 776 |
else if (count($this->cc) == 0) |
|
| 777 |
$result .= $this->HeaderLine("To", "undisclosed-recipients:;");
|
|
| 778 |
if(count($this->cc) > 0) |
|
| 779 |
$result .= $this->AddrAppend("Cc", $this->cc);
|
|
| 780 |
} |
|
| 671 |
/** |
|
| 672 |
* Formats an address correctly. |
|
| 673 |
* @access private |
|
| 674 |
* @return string |
|
| 675 |
*/ |
|
| 676 |
function AddrFormat($addr) {
|
|
| 677 |
if(empty($addr[1])) {
|
|
| 678 |
$formatted = $this->SecureHeader($addr[0]); |
|
| 679 |
} else {
|
|
| 680 |
$formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 681 |
} |
|
| 781 | 682 |
|
| 782 |
$from = array(); |
|
| 783 |
$from[0][0] = trim($this->From); |
|
| 784 |
$from[0][1] = $this->FromName; |
|
| 785 |
$result .= $this->AddrAppend("From", $from);
|
|
| 683 |
return $formatted; |
|
| 684 |
} |
|
| 786 | 685 |
|
| 787 |
// sendmail and mail() extract Bcc from the header before sending |
|
| 788 |
if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0)) |
|
| 789 |
$result .= $this->AddrAppend("Bcc", $this->bcc);
|
|
| 686 |
/** |
|
| 687 |
* Wraps message for use with mailers that do not |
|
| 688 |
* automatically perform wrapping and for quoted-printable. |
|
| 689 |
* Original written by philippe. |
|
| 690 |
* @access private |
|
| 691 |
* @return string |
|
| 692 |
*/ |
|
| 693 |
function WrapText($message, $length, $qp_mode = false) {
|
|
| 694 |
$soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
|
|
| 790 | 695 |
|
| 791 |
if(count($this->ReplyTo) > 0) |
|
| 792 |
$result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
|
|
| 696 |
$message = $this->FixEOL($message); |
|
| 697 |
if (substr($message, -1) == $this->LE) {
|
|
| 698 |
$message = substr($message, 0, -1); |
|
| 699 |
} |
|
| 793 | 700 |
|
| 794 |
// mail() sets the subject itself |
|
| 795 |
if($this->Mailer != "mail") |
|
| 796 |
$result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
|
|
| 701 |
$line = explode($this->LE, $message); |
|
| 702 |
$message = ''; |
|
| 703 |
for ($i=0 ;$i < count($line); $i++) {
|
|
| 704 |
$line_part = explode(' ', $line[$i]);
|
|
| 705 |
$buf = ''; |
|
| 706 |
for ($e = 0; $e<count($line_part); $e++) {
|
|
| 707 |
$word = $line_part[$e]; |
|
| 708 |
if ($qp_mode and (strlen($word) > $length)) {
|
|
| 709 |
$space_left = $length - strlen($buf) - 1; |
|
| 710 |
if ($e != 0) {
|
|
| 711 |
if ($space_left > 20) {
|
|
| 712 |
$len = $space_left; |
|
| 713 |
if (substr($word, $len - 1, 1) == '=') {
|
|
| 714 |
$len--; |
|
| 715 |
} elseif (substr($word, $len - 2, 1) == '=') {
|
|
| 716 |
$len -= 2; |
|
| 717 |
} |
|
| 718 |
$part = substr($word, 0, $len); |
|
| 719 |
$word = substr($word, $len); |
|
| 720 |
$buf .= ' ' . $part; |
|
| 721 |
$message .= $buf . sprintf("=%s", $this->LE);
|
|
| 722 |
} else {
|
|
| 723 |
$message .= $buf . $soft_break; |
|
| 724 |
} |
|
| 725 |
$buf = ''; |
|
| 726 |
} |
|
| 727 |
while (strlen($word) > 0) {
|
|
| 728 |
$len = $length; |
|
| 729 |
if (substr($word, $len - 1, 1) == '=') {
|
|
| 730 |
$len--; |
|
| 731 |
} elseif (substr($word, $len - 2, 1) == '=') {
|
|
| 732 |
$len -= 2; |
|
| 733 |
} |
|
| 734 |
$part = substr($word, 0, $len); |
|
| 735 |
$word = substr($word, $len); |
|
| 797 | 736 |
|
| 798 |
$result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
|
|
| 799 |
$result .= $this->HeaderLine("X-Priority", $this->Priority);
|
|
| 800 |
$result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]");
|
|
| 801 |
|
|
| 802 |
if($this->ConfirmReadingTo != "")
|
|
| 803 |
{
|
|
| 804 |
$result .= $this->HeaderLine("Disposition-Notification-To",
|
|
| 805 |
"<" . trim($this->ConfirmReadingTo) . ">");
|
|
| 806 |
}
|
|
| 737 |
if (strlen($word) > 0) {
|
|
| 738 |
$message .= $part . sprintf("=%s", $this->LE);
|
|
| 739 |
} else {
|
|
| 740 |
$buf = $part; |
|
| 741 |
}
|
|
| 742 |
}
|
|
| 743 |
} else {
|
|
| 744 |
$buf_o = $buf;
|
|
| 745 |
$buf .= ($e == 0) ? $word : (' ' . $word);
|
|
| 807 | 746 |
|
| 808 |
// Add custom headers |
|
| 809 |
for($index = 0; $index < count($this->CustomHeader); $index++) |
|
| 810 |
{
|
|
| 811 |
$result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), |
|
| 812 |
$this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|
| 747 |
if (strlen($buf) > $length and $buf_o != '') {
|
|
| 748 |
$message .= $buf_o . $soft_break; |
|
| 749 |
$buf = $word; |
|
| 750 |
} |
|
| 813 | 751 |
} |
| 814 |
$result .= $this->HeaderLine("MIME-Version", "1.0");
|
|
| 752 |
} |
|
| 753 |
$message .= $buf . $this->LE; |
|
| 754 |
} |
|
| 815 | 755 |
|
| 816 |
switch($this->message_type) |
|
| 817 |
{
|
|
| 818 |
case "plain": |
|
| 819 |
$result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
|
|
| 820 |
$result .= sprintf("Content-Type: %s; charset=\"%s\"",
|
|
| 821 |
$this->ContentType, $this->CharSet); |
|
| 822 |
break; |
|
| 823 |
case "attachments": |
|
| 824 |
// fall through |
|
| 825 |
case "alt_attachments": |
|
| 826 |
if($this->InlineImageExists()) |
|
| 827 |
{
|
|
| 828 |
$result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
|
|
| 829 |
"multipart/related", $this->LE, $this->LE, |
|
| 830 |
$this->boundary[1], $this->LE); |
|
| 831 |
} |
|
| 832 |
else |
|
| 833 |
{
|
|
| 834 |
$result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
|
|
| 835 |
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
|
|
| 836 |
} |
|
| 837 |
break; |
|
| 838 |
case "alt": |
|
| 839 |
$result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
|
|
| 840 |
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
|
|
| 841 |
break; |
|
| 842 |
} |
|
| 756 |
return $message; |
|
| 757 |
} |
|
| 843 | 758 |
|
| 844 |
if($this->Mailer != "mail") |
|
| 845 |
$result .= $this->LE.$this->LE; |
|
| 759 |
/** |
|
| 760 |
* Set the body wrapping. |
|
| 761 |
* @access private |
|
| 762 |
* @return void |
|
Also available in: Unified diff
updated PHPMailer framework to version 2.0.0 (/include/phpmailer)