| 19 | | class PHPMailer |
|---|
| 20 | | { |
|---|
| 21 | | ///////////////////////////////////////////////// |
|---|
| 22 | | // PUBLIC VARIABLES |
|---|
| 23 | | ///////////////////////////////////////////////// |
|---|
| 24 | | |
|---|
| 25 | | /** |
|---|
| 26 | | * Email priority (1 = High, 3 = Normal, 5 = low). |
|---|
| 27 | | * @var int |
|---|
| 28 | | */ |
|---|
| 29 | | var $Priority = 3; |
|---|
| 30 | | |
|---|
| 31 | | /** |
|---|
| 32 | | * Sets the CharSet of the message. |
|---|
| 33 | | * @var string |
|---|
| 34 | | */ |
|---|
| 35 | | var $CharSet = "UTF-8"; |
|---|
| 36 | | |
|---|
| 37 | | /** |
|---|
| 38 | | * Sets the Content-type of the message. |
|---|
| 39 | | * @var string |
|---|
| 40 | | */ |
|---|
| 41 | | var $ContentType = "text/plain"; |
|---|
| 42 | | |
|---|
| 43 | | /** |
|---|
| 44 | | * Sets the Encoding of the message. Options for this are "8bit", |
|---|
| 45 | | * "7bit", "binary", "base64", and "quoted-printable". |
|---|
| 46 | | * @var string |
|---|
| 47 | | */ |
|---|
| 48 | | var $Encoding = "8bit"; |
|---|
| 49 | | |
|---|
| 50 | | /** |
|---|
| 51 | | * Holds the most recent mailer error message. |
|---|
| 52 | | * @var string |
|---|
| 53 | | */ |
|---|
| 54 | | var $ErrorInfo = ""; |
|---|
| 55 | | |
|---|
| 56 | | /** |
|---|
| 57 | | * Sets the From email address for the message. |
|---|
| 58 | | * @var string |
|---|
| 59 | | */ |
|---|
| 60 | | var $From = "localhost.localdomain"; |
|---|
| 61 | | |
|---|
| 62 | | /** |
|---|
| 63 | | * Sets the From name of the message. |
|---|
| 64 | | * @var string |
|---|
| 65 | | */ |
|---|
| 66 | | var $FromName = "Support"; |
|---|
| 67 | | |
|---|
| 68 | | /** |
|---|
| 69 | | * Sets the Sender email (Return-Path) of the message. If not empty, |
|---|
| 70 | | * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
|---|
| 71 | | * @var string |
|---|
| 72 | | */ |
|---|
| 73 | | var $Sender = ""; |
|---|
| 74 | | |
|---|
| 75 | | /** |
|---|
| 76 | | * Sets the Subject of the message. |
|---|
| 77 | | * @var string |
|---|
| 78 | | */ |
|---|
| 79 | | var $Subject = ""; |
|---|
| 80 | | |
|---|
| 81 | | /** |
|---|
| 82 | | * Sets the Body of the message. This can be either an HTML or text body. |
|---|
| 83 | | * If HTML then run IsHTML(true). |
|---|
| 84 | | * @var string |
|---|
| 85 | | */ |
|---|
| 86 | | var $Body = ""; |
|---|
| 87 | | |
|---|
| 88 | | /** |
|---|
| 89 | | * Sets the text-only body of the message. This automatically sets the |
|---|
| 90 | | * email to multipart/alternative. This body can be read by mail |
|---|
| 91 | | * clients that do not have HTML email capability such as mutt. Clients |
|---|
| 92 | | * that can read HTML will view the normal Body. |
|---|
| 93 | | * @var string |
|---|
| 94 | | */ |
|---|
| 95 | | var $AltBody = ""; |
|---|
| 96 | | |
|---|
| 97 | | /** |
|---|
| 98 | | * Sets word wrapping on the body of the message to a given number of |
|---|
| 99 | | * characters. |
|---|
| 100 | | * @var int |
|---|
| 101 | | */ |
|---|
| 102 | | var $WordWrap = 0; |
|---|
| 103 | | |
|---|
| 104 | | /** |
|---|
| 105 | | * Method to send mail: ("mail", "sendmail", or "smtp"). |
|---|
| 106 | | * @var string |
|---|
| 107 | | */ |
|---|
| 108 | | var $Mailer = "mail"; |
|---|
| 109 | | |
|---|
| 110 | | /** |
|---|
| 111 | | * Sets the path of the sendmail program. |
|---|
| 112 | | * @var string |
|---|
| 113 | | */ |
|---|
| 114 | | var $Sendmail = "/usr/sbin/sendmail"; |
|---|
| 115 | | |
|---|
| 116 | | /** |
|---|
| 117 | | * Path to PHPMailer plugins. This is now only useful if the SMTP class |
|---|
| 118 | | * is in a different directory than the PHP include path. |
|---|
| 119 | | * @var string |
|---|
| 120 | | */ |
|---|
| 121 | | var $PluginDir = ""; |
|---|
| 122 | | |
|---|
| 123 | | /** |
|---|
| 124 | | * Holds PHPMailer version. |
|---|
| 125 | | * @var string |
|---|
| 126 | | */ |
|---|
| 127 | | var $Version = "1.73"; |
|---|
| 128 | | |
|---|
| 129 | | /** |
|---|
| 130 | | * Sets the email address that a reading confirmation will be sent. |
|---|
| 131 | | * @var string |
|---|
| 132 | | */ |
|---|
| 133 | | var $ConfirmReadingTo = ""; |
|---|
| 134 | | |
|---|
| 135 | | /** |
|---|
| 136 | | * Sets the hostname to use in Message-Id and Received headers |
|---|
| 137 | | * and as default HELO string. If empty, the value returned |
|---|
| 138 | | * by SERVER_NAME is used or 'localhost.localdomain'. |
|---|
| 139 | | * @var string |
|---|
| 140 | | */ |
|---|
| 141 | | var $Hostname = ""; |
|---|
| 142 | | |
|---|
| 143 | | ///////////////////////////////////////////////// |
|---|
| 144 | | // SMTP VARIABLES |
|---|
| 145 | | ///////////////////////////////////////////////// |
|---|
| 146 | | |
|---|
| 147 | | /** |
|---|
| 148 | | * Sets the SMTP hosts. All hosts must be separated by a |
|---|
| 149 | | * semicolon. You can also specify a different port |
|---|
| 150 | | * for each host by using this format: [hostname:port] |
|---|
| 151 | | * (e.g. "smtp1.example.com:25;smtp2.example.com"). |
|---|
| 152 | | * Hosts will be tried in order. |
|---|
| 153 | | * @var string |
|---|
| 154 | | */ |
|---|
| 155 | | var $Host = "localhost"; |
|---|
| 156 | | |
|---|
| 157 | | /** |
|---|
| 158 | | * Sets the default SMTP server port. |
|---|
| 159 | | * @var int |
|---|
| 160 | | */ |
|---|
| 161 | | var $Port = 25; |
|---|
| 162 | | |
|---|
| 163 | | /** |
|---|
| 164 | | * Sets the SMTP HELO of the message (Default is $Hostname). |
|---|
| 165 | | * @var string |
|---|
| 166 | | */ |
|---|
| 167 | | var $Helo = ""; |
|---|
| 168 | | |
|---|
| 169 | | /** |
|---|
| 170 | | * Sets SMTP authentication. Utilizes the Username and Password variables. |
|---|
| 171 | | * @var bool |
|---|
| 172 | | */ |
|---|
| 173 | | var $SMTPAuth = false; |
|---|
| 174 | | |
|---|
| 175 | | /** |
|---|
| 176 | | * Sets SMTP username. |
|---|
| 177 | | * @var string |
|---|
| 178 | | */ |
|---|
| 179 | | var $Username = ""; |
|---|
| 180 | | |
|---|
| 181 | | /** |
|---|
| 182 | | * Sets SMTP password. |
|---|
| 183 | | * @var string |
|---|
| 184 | | */ |
|---|
| 185 | | var $Password = ""; |
|---|
| 186 | | |
|---|
| 187 | | /** |
|---|
| 188 | | * Sets the SMTP server timeout in seconds. This function will not |
|---|
| 189 | | * work with the win32 version. |
|---|
| 190 | | * @var int |
|---|
| 191 | | */ |
|---|
| 192 | | var $Timeout = 10; |
|---|
| 193 | | |
|---|
| 194 | | /** |
|---|
| 195 | | * Sets SMTP class debugging on or off. |
|---|
| 196 | | * @var bool |
|---|
| 197 | | */ |
|---|
| 198 | | var $SMTPDebug = false; |
|---|
| 199 | | |
|---|
| 200 | | /** |
|---|
| 201 | | * Prevents the SMTP connection from being closed after each mail |
|---|
| 202 | | * sending. If this is set to true then to close the connection |
|---|
| 203 | | * requires an explicit call to SmtpClose(). |
|---|
| 204 | | * @var bool |
|---|
| 205 | | */ |
|---|
| 206 | | var $SMTPKeepAlive = false; |
|---|
| 207 | | |
|---|
| 208 | | /**#@+ |
|---|
| 209 | | * @access private |
|---|
| 210 | | */ |
|---|
| 211 | | var $smtp = NULL; |
|---|
| 212 | | var $to = array(); |
|---|
| 213 | | var $cc = array(); |
|---|
| 214 | | var $bcc = array(); |
|---|
| 215 | | var $ReplyTo = array(); |
|---|
| 216 | | var $attachment = array(); |
|---|
| 217 | | var $CustomHeader = array(); |
|---|
| 218 | | var $message_type = ""; |
|---|
| 219 | | var $boundary = array(); |
|---|
| 220 | | var $language = array(); |
|---|
| 221 | | var $error_count = 0; |
|---|
| 222 | | var $LE = "\n"; |
|---|
| 223 | | /**#@-*/ |
|---|
| 224 | | |
|---|
| 225 | | ///////////////////////////////////////////////// |
|---|
| 226 | | // VARIABLE METHODS |
|---|
| 227 | | ///////////////////////////////////////////////// |
|---|
| 228 | | |
|---|
| 229 | | /** |
|---|
| 230 | | * Sets message type to HTML. |
|---|
| 231 | | * @param bool $bool |
|---|
| 232 | | * @return void |
|---|
| 233 | | */ |
|---|
| 234 | | function IsHTML($bool) { |
|---|
| 235 | | if($bool == true) |
|---|
| 236 | | $this->ContentType = "text/html"; |
|---|
| 237 | | else |
|---|
| 238 | | $this->ContentType = "text/plain"; |
|---|
| 239 | | } |
|---|
| 240 | | |
|---|
| 241 | | /** |
|---|
| 242 | | * Sets Mailer to send message using SMTP. |
|---|
| 243 | | * @return void |
|---|
| 244 | | */ |
|---|
| 245 | | function IsSMTP() { |
|---|
| 246 | | $this->Mailer = "smtp"; |
|---|
| 247 | | } |
|---|
| 248 | | |
|---|
| 249 | | /** |
|---|
| 250 | | * Sets Mailer to send message using PHP mail() function. |
|---|
| 251 | | * @return void |
|---|
| 252 | | */ |
|---|
| 253 | | function IsMail() { |
|---|
| 254 | | $this->Mailer = "mail"; |
|---|
| 255 | | } |
|---|
| 256 | | |
|---|
| 257 | | /** |
|---|
| 258 | | * Sets Mailer to send message using the $Sendmail program. |
|---|
| 259 | | * @return void |
|---|
| 260 | | */ |
|---|
| 261 | | function IsSendmail() { |
|---|
| 262 | | $this->Mailer = "sendmail"; |
|---|
| 263 | | } |
|---|
| 264 | | |
|---|
| 265 | | /** |
|---|
| 266 | | * Sets Mailer to send message using the qmail MTA. |
|---|
| 267 | | * @return void |
|---|
| 268 | | */ |
|---|
| 269 | | function IsQmail() { |
|---|
| 270 | | $this->Sendmail = "/var/qmail/bin/sendmail"; |
|---|
| 271 | | $this->Mailer = "sendmail"; |
|---|
| 272 | | } |
|---|
| 273 | | |
|---|
| 274 | | |
|---|
| 275 | | ///////////////////////////////////////////////// |
|---|
| 276 | | // RECIPIENT METHODS |
|---|
| 277 | | ///////////////////////////////////////////////// |
|---|
| 278 | | |
|---|
| 279 | | /** |
|---|
| 280 | | * Adds a "To" address. |
|---|
| 281 | | * @param string $address |
|---|
| 282 | | * @param string $name |
|---|
| 283 | | * @return void |
|---|
| 284 | | */ |
|---|
| 285 | | function AddAddress($address, $name = "") { |
|---|
| 286 | | $cur = count($this->to); |
|---|
| 287 | | $this->to[$cur][0] = trim($address); |
|---|
| 288 | | $this->to[$cur][1] = $name; |
|---|
| 289 | | } |
|---|
| 290 | | |
|---|
| 291 | | /** |
|---|
| 292 | | * Adds a "Cc" address. Note: this function works |
|---|
| 293 | | * with the SMTP mailer on win32, not with the "mail" |
|---|
| 294 | | * mailer. |
|---|
| 295 | | * @param string $address |
|---|
| 296 | | * @param string $name |
|---|
| 297 | | * @return void |
|---|
| 298 | | */ |
|---|
| 299 | | function AddCC($address, $name = "") { |
|---|
| 300 | | $cur = count($this->cc); |
|---|
| 301 | | $this->cc[$cur][0] = trim($address); |
|---|
| 302 | | $this->cc[$cur][1] = $name; |
|---|
| 303 | | } |
|---|
| 304 | | |
|---|
| 305 | | /** |
|---|
| 306 | | * Adds a "Bcc" address. Note: this function works |
|---|
| 307 | | * with the SMTP mailer on win32, not with the "mail" |
|---|
| 308 | | * mailer. |
|---|
| 309 | | * @param string $address |
|---|
| 310 | | * @param string $name |
|---|
| 311 | | * @return void |
|---|
| 312 | | */ |
|---|
| 313 | | function AddBCC($address, $name = "") { |
|---|
| 314 | | $cur = count($this->bcc); |
|---|
| 315 | | $this->bcc[$cur][0] = trim($address); |
|---|
| 316 | | $this->bcc[$cur][1] = $name; |
|---|
| 317 | | } |
|---|
| 318 | | |
|---|
| 319 | | /** |
|---|
| 320 | | * Adds a "Reply-to" address. |
|---|
| 321 | | * @param string $address |
|---|
| 322 | | * @param string $name |
|---|
| 323 | | * @return void |
|---|
| 324 | | */ |
|---|
| 325 | | function AddReplyTo($address, $name = "") { |
|---|
| 326 | | $cur = count($this->ReplyTo); |
|---|
| 327 | | $this->ReplyTo[$cur][0] = trim($address); |
|---|
| 328 | | $this->ReplyTo[$cur][1] = $name; |
|---|
| 329 | | } |
|---|
| 330 | | |
|---|
| 331 | | |
|---|
| 332 | | ///////////////////////////////////////////////// |
|---|
| 333 | | // MAIL SENDING METHODS |
|---|
| 334 | | ///////////////////////////////////////////////// |
|---|
| 335 | | |
|---|
| 336 | | /** |
|---|
| 337 | | * Creates message and assigns Mailer. If the message is |
|---|
| 338 | | * not sent successfully then it returns false. Use the ErrorInfo |
|---|
| 339 | | * variable to view description of the error. |
|---|
| 340 | | * @return bool |
|---|
| 341 | | */ |
|---|
| 342 | | function Send() { |
|---|
| 343 | | $header = ""; |
|---|
| 344 | | $body = ""; |
|---|
| 345 | | $result = true; |
|---|
| 346 | | |
|---|
| 347 | | if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) |
|---|
| 348 | | { |
|---|
| 349 | | $this->SetError($this->Lang("provide_address")); |
|---|
| 350 | | return false; |
|---|
| | 33 | |
|---|
| | 34 | class PHPMailer { |
|---|
| | 35 | |
|---|
| | 36 | ///////////////////////////////////////////////// |
|---|
| | 37 | // PROPERTIES, PUBLIC |
|---|
| | 38 | ///////////////////////////////////////////////// |
|---|
| | 39 | |
|---|
| | 40 | /** |
|---|
| | 41 | * Email priority (1 = High, 3 = Normal, 5 = low). |
|---|
| | 42 | * @var int |
|---|
| | 43 | */ |
|---|
| | 44 | var $Priority = 3; |
|---|
| | 45 | |
|---|
| | 46 | /** |
|---|
| | 47 | * Sets the CharSet of the message. |
|---|
| | 48 | * @var string |
|---|
| | 49 | */ |
|---|
| | 50 | var $CharSet = 'iso-8859-1'; |
|---|
| | 51 | |
|---|
| | 52 | /** |
|---|
| | 53 | * Sets the Content-type of the message. |
|---|
| | 54 | * @var string |
|---|
| | 55 | */ |
|---|
| | 56 | var $ContentType = 'text/plain'; |
|---|
| | 57 | |
|---|
| | 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'; |
|---|
| | 64 | |
|---|
| | 65 | /** |
|---|
| | 66 | * Holds the most recent mailer error message. |
|---|
| | 67 | * @var string |
|---|
| | 68 | */ |
|---|
| | 69 | var $ErrorInfo = ''; |
|---|
| | 70 | |
|---|
| | 71 | /** |
|---|
| | 72 | * Sets the From email address for the message. |
|---|
| | 73 | * @var string |
|---|
| | 74 | */ |
|---|
| | 75 | var $From = 'root@localhost'; |
|---|
| | 76 | |
|---|
| | 77 | /** |
|---|
| | 78 | * Sets the From name of the message. |
|---|
| | 79 | * @var string |
|---|
| | 80 | */ |
|---|
| | 81 | var $FromName = 'Root User'; |
|---|
| | 82 | |
|---|
| | 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 = ''; |
|---|
| | 89 | |
|---|
| | 90 | /** |
|---|
| | 91 | * Sets the Subject of the message. |
|---|
| | 92 | * @var string |
|---|
| | 93 | */ |
|---|
| | 94 | var $Subject = ''; |
|---|
| | 95 | |
|---|
| | 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 = ''; |
|---|
| | 102 | |
|---|
| | 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 = ''; |
|---|
| | 111 | |
|---|
| | 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; |
|---|
| | 118 | |
|---|
| | 119 | /** |
|---|
| | 120 | * Method to send mail: ("mail", "sendmail", or "smtp"). |
|---|
| | 121 | * @var string |
|---|
| | 122 | */ |
|---|
| | 123 | var $Mailer = 'mail'; |
|---|
| | 124 | |
|---|
| | 125 | /** |
|---|
| | 126 | * Sets the path of the sendmail program. |
|---|
| | 127 | * @var string |
|---|
| | 128 | */ |
|---|
| | 129 | var $Sendmail = '/usr/sbin/sendmail'; |
|---|
| | 130 | |
|---|
| | 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 = ''; |
|---|
| | 137 | |
|---|
| | 138 | /** |
|---|
| | 139 | * Holds PHPMailer version. |
|---|
| | 140 | * @var string |
|---|
| | 141 | */ |
|---|
| | 142 | var $Version = "2.0.2"; |
|---|
| | 143 | |
|---|
| | 144 | /** |
|---|
| | 145 | * Sets the email address that a reading confirmation will be sent. |
|---|
| | 146 | * @var string |
|---|
| | 147 | */ |
|---|
| | 148 | var $ConfirmReadingTo = ''; |
|---|
| | 149 | |
|---|
| | 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 = ''; |
|---|
| | 157 | |
|---|
| | 158 | /** |
|---|
| | 159 | * Sets the message ID to be used in the Message-Id header. |
|---|
| | 160 | * If empty, a unique id will be generated. |
|---|
| | 161 | * @var string |
|---|
| | 162 | */ |
|---|
| | 163 | var $MessageID = ''; |
|---|
| | 164 | |
|---|
| | 165 | ///////////////////////////////////////////////// |
|---|
| | 166 | // PROPERTIES FOR SMTP |
|---|
| | 167 | ///////////////////////////////////////////////// |
|---|
| | 168 | |
|---|
| | 169 | /** |
|---|
| | 170 | * Sets the SMTP hosts. All hosts must be separated by a |
|---|
| | 171 | * semicolon. You can also specify a different port |
|---|
| | 172 | * for each host by using this format: [hostname:port] |
|---|
| | 173 | * (e.g. "smtp1.example.com:25;smtp2.example.com"). |
|---|
| | 174 | * Hosts will be tried in order. |
|---|
| | 175 | * @var string |
|---|
| | 176 | */ |
|---|
| | 177 | var $Host = 'localhost'; |
|---|
| | 178 | |
|---|
| | 179 | /** |
|---|
| | 180 | * Sets the default SMTP server port. |
|---|
| | 181 | * @var int |
|---|
| | 182 | */ |
|---|
| | 183 | var $Port = 25; |
|---|
| | 184 | |
|---|
| | 185 | /** |
|---|
| | 186 | * Sets the SMTP HELO of the message (Default is $Hostname). |
|---|
| | 187 | * @var string |
|---|
| | 188 | */ |
|---|
| | 189 | var $Helo = ''; |
|---|
| | 190 | |
|---|
| | 191 | /** |
|---|
| | 192 | * Sets connection prefix. |
|---|
| | 193 | * Options are "", "ssl" or "tls" |
|---|
| | 194 | * @var string |
|---|
| | 195 | */ |
|---|
| | 196 | var $SMTPSecure = ""; |
|---|
| | 197 | |
|---|
| | 198 | /** |
|---|
| | 199 | * Sets SMTP authentication. Utilizes the Username and Password variables. |
|---|
| | 200 | * @var bool |
|---|
| | 201 | */ |
|---|
| | 202 | var $SMTPAuth = false; |
|---|
| | 203 | |
|---|
| | 204 | /** |
|---|
| | 205 | * Sets SMTP username. |
|---|
| | 206 | * @var string |
|---|
| | 207 | */ |
|---|
| | 208 | var $Username = ''; |
|---|
| | 209 | |
|---|
| | 210 | /** |
|---|
| | 211 | * Sets SMTP password. |
|---|
| | 212 | * @var string |
|---|
| | 213 | */ |
|---|
| | 214 | var $Password = ''; |
|---|
| | 215 | |
|---|
| | 216 | /** |
|---|
| | 217 | * Sets the SMTP server timeout in seconds. This function will not |
|---|
| | 218 | * work with the win32 version. |
|---|
| | 219 | * @var int |
|---|
| | 220 | */ |
|---|
| | 221 | var $Timeout = 10; |
|---|
| | 222 | |
|---|
| | 223 | /** |
|---|
| | 224 | * Sets SMTP class debugging on or off. |
|---|
| | 225 | * @var bool |
|---|
| | 226 | */ |
|---|
| | 227 | var $SMTPDebug = false; |
|---|
| | 228 | |
|---|
| | 229 | /** |
|---|
| | 230 | * Prevents the SMTP connection from being closed after each mail |
|---|
| | 231 | * sending. If this is set to true then to close the connection |
|---|
| | 232 | * requires an explicit call to SmtpClose(). |
|---|
| | 233 | * @var bool |
|---|
| | 234 | */ |
|---|
| | 235 | var $SMTPKeepAlive = false; |
|---|
| | 236 | |
|---|
| | 237 | /** |
|---|
| | 238 | * Provides the ability to have the TO field process individual |
|---|
| | 239 | * emails, instead of sending to entire TO addresses |
|---|
| | 240 | * @var bool |
|---|
| | 241 | */ |
|---|
| | 242 | var $SingleTo = false; |
|---|
| | 243 | |
|---|
| | 244 | ///////////////////////////////////////////////// |
|---|
| | 245 | // PROPERTIES, PRIVATE |
|---|
| | 246 | ///////////////////////////////////////////////// |
|---|
| | 247 | |
|---|
| | 248 | var $smtp = NULL; |
|---|
| | 249 | var $to = array(); |
|---|
| | 250 | var $cc = array(); |
|---|
| | 251 | var $bcc = array(); |
|---|
| | 252 | var $ReplyTo = array(); |
|---|
| | 253 | var $attachment = array(); |
|---|
| | 254 | var $CustomHeader = array(); |
|---|
| | 255 | var $message_type = ''; |
|---|
| | 256 | var $boundary = array(); |
|---|
| | 257 | var $language = array(); |
|---|
| | 258 | var $error_count = 0; |
|---|
| | 259 | var $LE = "\n"; |
|---|
| | 260 | var $sign_key_file = ""; |
|---|
| | 261 | var $sign_key_pass = ""; |
|---|
| | 262 | |
|---|
| | 263 | ///////////////////////////////////////////////// |
|---|
| | 264 | // METHODS, VARIABLES |
|---|
| | 265 | ///////////////////////////////////////////////// |
|---|
| | 266 | |
|---|
| | 267 | /** |
|---|
| | 268 | * Sets message type to HTML. |
|---|
| | 269 | * @param bool $bool |
|---|
| | 270 | * @return void |
|---|
| | 271 | */ |
|---|
| | 272 | function IsHTML($bool) { |
|---|
| | 273 | if($bool == true) { |
|---|
| | 274 | $this->ContentType = 'text/html'; |
|---|
| | 275 | } else { |
|---|
| | 276 | $this->ContentType = 'text/plain'; |
|---|
| | 277 | } |
|---|
| | 278 | } |
|---|
| | 279 | |
|---|
| | 280 | /** |
|---|
| | 281 | * Sets Mailer to send message using SMTP. |
|---|
| | 282 | * @return void |
|---|
| | 283 | */ |
|---|
| | 284 | function IsSMTP() { |
|---|
| | 285 | $this->Mailer = 'smtp'; |
|---|
| | 286 | } |
|---|
| | 287 | |
|---|
| | 288 | /** |
|---|
| | 289 | * Sets Mailer to send message using PHP mail() function. |
|---|
| | 290 | * @return void |
|---|
| | 291 | */ |
|---|
| | 292 | function IsMail() { |
|---|
| | 293 | $this->Mailer = 'mail'; |
|---|
| | 294 | } |
|---|
| | 295 | |
|---|
| | 296 | /** |
|---|
| | 297 | * Sets Mailer to send message using the $Sendmail program. |
|---|
| | 298 | * @return void |
|---|
| | 299 | */ |
|---|
| | 300 | function IsSendmail() { |
|---|
| | 301 | $this->Mailer = 'sendmail'; |
|---|
| | 302 | } |
|---|
| | 303 | |
|---|
| | 304 | /** |
|---|
| | 305 | * Sets Mailer to send message using the qmail MTA. |
|---|
| | 306 | * @return void |
|---|
| | 307 | */ |
|---|
| | 308 | function IsQmail() { |
|---|
| | 309 | $this->Sendmail = '/var/qmail/bin/sendmail'; |
|---|
| | 310 | $this->Mailer = 'sendmail'; |
|---|
| | 311 | } |
|---|
| | 312 | |
|---|
| | 313 | ///////////////////////////////////////////////// |
|---|
| | 314 | // METHODS, RECIPIENTS |
|---|
| | 315 | ///////////////////////////////////////////////// |
|---|
| | 316 | |
|---|
| | 317 | /** |
|---|
| | 318 | * Adds a "To" address. |
|---|
| | 319 | * @param string $address |
|---|
| | 320 | * @param string $name |
|---|
| | 321 | * @return void |
|---|
| | 322 | */ |
|---|
| | 323 | function AddAddress($address, $name = '') { |
|---|
| | 324 | $cur = count($this->to); |
|---|
| | 325 | $this->to[$cur][0] = trim($address); |
|---|
| | 326 | $this->to[$cur][1] = $name; |
|---|
| | 327 | } |
|---|
| | 328 | |
|---|
| | 329 | /** |
|---|
| | 330 | * Adds a "Cc" address. Note: this function works |
|---|
| | 331 | * with the SMTP mailer on win32, not with the "mail" |
|---|
| | 332 | * mailer. |
|---|
| | 333 | * @param string $address |
|---|
| | 334 | * @param string $name |
|---|
| | 335 | * @return void |
|---|
| | 336 | */ |
|---|
| | 337 | function AddCC($address, $name = '') { |
|---|
| | 338 | $cur = count($this->cc); |
|---|
| | 339 | $this->cc[$cur][0] = trim($address); |
|---|
| | 340 | $this->cc[$cur][1] = $name; |
|---|
| | 341 | } |
|---|
| | 342 | |
|---|
| | 343 | /** |
|---|
| | 344 | * Adds a "Bcc" address. Note: this function works |
|---|
| | 345 | * with the SMTP mailer on win32, not with the "mail" |
|---|
| | 346 | * mailer. |
|---|
| | 347 | * @param string $address |
|---|
| | 348 | * @param string $name |
|---|
| | 349 | * @return void |
|---|
| | 350 | */ |
|---|
| | 351 | function AddBCC($address, $name = '') { |
|---|
| | 352 | $cur = count($this->bcc); |
|---|
| | 353 | $this->bcc[$cur][0] = trim($address); |
|---|
| | 354 | $this->bcc[$cur][1] = $name; |
|---|
| | 355 | } |
|---|
| | 356 | |
|---|
| | 357 | /** |
|---|
| | 358 | * Adds a "Reply-To" address. |
|---|
| | 359 | * @param string $address |
|---|
| | 360 | * @param string $name |
|---|
| | 361 | * @return void |
|---|
| | 362 | */ |
|---|
| | 363 | function AddReplyTo($address, $name = '') { |
|---|
| | 364 | $cur = count($this->ReplyTo); |
|---|
| | 365 | $this->ReplyTo[$cur][0] = trim($address); |
|---|
| | 366 | $this->ReplyTo[$cur][1] = $name; |
|---|
| | 367 | } |
|---|
| | 368 | |
|---|
| | 369 | ///////////////////////////////////////////////// |
|---|
| | 370 | // METHODS, MAIL SENDING |
|---|
| | 371 | ///////////////////////////////////////////////// |
|---|
| | 372 | |
|---|
| | 373 | /** |
|---|
| | 374 | * Creates message and assigns Mailer. If the message is |
|---|
| | 375 | * not sent successfully then it returns false. Use the ErrorInfo |
|---|
| | 376 | * variable to view description of the error. |
|---|
| | 377 | * @return bool |
|---|
| | 378 | */ |
|---|
| | 379 | function Send() { |
|---|
| | 380 | $header = ''; |
|---|
| | 381 | $body = ''; |
|---|
| | 382 | $result = true; |
|---|
| | 383 | |
|---|
| | 384 | if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|---|
| | 385 | $this->SetError($this->Lang('provide_address')); |
|---|
| | 386 | return false; |
|---|
| | 387 | } |
|---|
| | 388 | |
|---|
| | 389 | /* Set whether the message is multipart/alternative */ |
|---|
| | 390 | if(!empty($this->AltBody)) { |
|---|
| | 391 | $this->ContentType = 'multipart/alternative'; |
|---|
| | 392 | } |
|---|
| | 393 | |
|---|
| | 394 | $this->error_count = 0; // reset errors |
|---|
| | 395 | $this->SetMessageType(); |
|---|
| | 396 | $header .= $this->CreateHeader(); |
|---|
| | 397 | $body = $this->CreateBody(); |
|---|
| | 398 | |
|---|
| | 399 | if($body == '') { |
|---|
| | 400 | return false; |
|---|
| | 401 | } |
|---|
| | 402 | |
|---|
| | 403 | /* Choose the mailer */ |
|---|
| | 404 | switch($this->Mailer) { |
|---|
| | 405 | case 'sendmail': |
|---|
| | 406 | $result = $this->SendmailSend($header, $body); |
|---|
| | 407 | break; |
|---|
| | 408 | case 'smtp': |
|---|
| | 409 | $result = $this->SmtpSend($header, $body); |
|---|
| | 410 | break; |
|---|
| | 411 | case 'mail': |
|---|
| | 412 | $result = $this->MailSend($header, $body); |
|---|
| | 413 | break; |
|---|
| | 414 | default: |
|---|
| | 415 | $result = $this->MailSend($header, $body); |
|---|
| | 416 | break; |
|---|
| | 417 | //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported')); |
|---|
| | 418 | //$result = false; |
|---|
| | 419 | //break; |
|---|
| | 420 | } |
|---|
| | 421 | |
|---|
| | 422 | return $result; |
|---|
| | 423 | } |
|---|
| | 424 | |
|---|
| | 425 | /** |
|---|
| | 426 | * Sends mail using the $Sendmail program. |
|---|
| | 427 | * @access private |
|---|
| | 428 | * @return bool |
|---|
| | 429 | */ |
|---|
| | 430 | function SendmailSend($header, $body) { |
|---|
| | 431 | if ($this->Sender != '') { |
|---|
| | 432 | $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); |
|---|
| | 433 | } else { |
|---|
| | 434 | $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); |
|---|
| | 435 | } |
|---|
| | 436 | |
|---|
| | 437 | if(!@$mail = popen($sendmail, 'w')) { |
|---|
| | 438 | $this->SetError($this->Lang('execute') . $this->Sendmail); |
|---|
| | 439 | return false; |
|---|
| | 440 | } |
|---|
| | 441 | |
|---|
| | 442 | fputs($mail, $header); |
|---|
| | 443 | fputs($mail, $body); |
|---|
| | 444 | |
|---|
| | 445 | $result = pclose($mail); |
|---|
| | 446 | if (version_compare(phpversion(), '4.2.3') == -1) { |
|---|
| | 447 | $result = $result >> 8 & 0xFF; |
|---|
| | 448 | } |
|---|
| | 449 | if($result != 0) { |
|---|
| | 450 | $this->SetError($this->Lang('execute') . $this->Sendmail); |
|---|
| | 451 | return false; |
|---|
| | 452 | } |
|---|
| | 453 | return true; |
|---|
| | 454 | } |
|---|
| | 455 | |
|---|
| | 456 | /** |
|---|
| | 457 | * Sends mail using the PHP mail() function. |
|---|
| | 458 | * @access private |
|---|
| | 459 | * @return bool |
|---|
| | 460 | */ |
|---|
| | 461 | function MailSend($header, $body) { |
|---|
| | 462 | |
|---|
| | 463 | $to = ''; |
|---|
| | 464 | for($i = 0; $i < count($this->to); $i++) { |
|---|
| | 465 | if($i != 0) { $to .= ', '; } |
|---|
| | 466 | $to .= $this->AddrFormat($this->to[$i]); |
|---|
| | 467 | } |
|---|
| | 468 | |
|---|
| | 469 | $toArr = split(',', $to); |
|---|
| | 470 | |
|---|
| | 471 | $params = sprintf("-oi -f %s", $this->Sender); |
|---|
| | 472 | if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) { |
|---|
| | 473 | $old_from = ini_get('sendmail_from'); |
|---|
| | 474 | ini_set('sendmail_from', $this->Sender); |
|---|
| | 475 | if ($this->SingleTo === true && count($toArr) > 1) { |
|---|
| | 476 | foreach ($toArr as $key => $val) { |
|---|
| | 477 | $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|---|
| 427 | | |
|---|
| 428 | | if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1) |
|---|
| 429 | | { |
|---|
| 430 | | $old_from = ini_get("sendmail_from"); |
|---|
| 431 | | ini_set("sendmail_from", $this->Sender); |
|---|
| 432 | | $params = sprintf("-oi -f %s", $this->Sender); |
|---|
| 433 | | $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, |
|---|
| 434 | | $header, $params); |
|---|
| | 614 | } |
|---|
| | 615 | $index++; |
|---|
| | 616 | } |
|---|
| | 617 | if(!$connection) { |
|---|
| | 618 | $this->SetError($this->Lang('connect_host')); |
|---|
| | 619 | } |
|---|
| | 620 | |
|---|
| | 621 | return $connection; |
|---|
| | 622 | } |
|---|
| | 623 | |
|---|
| | 624 | /** |
|---|
| | 625 | * Closes the active SMTP session if one exists. |
|---|
| | 626 | * @return void |
|---|
| | 627 | */ |
|---|
| | 628 | function SmtpClose() { |
|---|
| | 629 | if($this->smtp != NULL) { |
|---|
| | 630 | if($this->smtp->Connected()) { |
|---|
| | 631 | $this->smtp->Quit(); |
|---|
| | 632 | $this->smtp->Close(); |
|---|
| | 633 | } |
|---|
| | 634 | } |
|---|
| | 635 | } |
|---|
| | 636 | |
|---|
| | 637 | /** |
|---|
| | 638 | * Sets the language for all class error messages. Returns false |
|---|
| | 639 | * if it cannot load the language file. The default language type |
|---|
| | 640 | * is English. |
|---|
| | 641 | * @param string $lang_type Type of language (e.g. Portuguese: "br") |
|---|
| | 642 | * @param string $lang_path Path to the language file directory |
|---|
| | 643 | * @access public |
|---|
| | 644 | * @return bool |
|---|
| | 645 | */ |
|---|
| | 646 | function SetLanguage($lang_type, $lang_path = 'language/') { |
|---|
| | 647 | if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) { |
|---|
| | 648 | include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); |
|---|
| | 649 | } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) { |
|---|
| | 650 | include($lang_path.'phpmailer.lang-en.php'); |
|---|
| | 651 | } else { |
|---|
| | 652 | $this->SetError('Could not load language file'); |
|---|
| | 653 | return false; |
|---|
| | 654 | } |
|---|
| | 655 | $this->language = $PHPMAILER_LANG; |
|---|
| | 656 | |
|---|
| | 657 | return true; |
|---|
| | 658 | } |
|---|
| | 659 | |
|---|
| | 660 | ///////////////////////////////////////////////// |
|---|
| | 661 | // METHODS, MESSAGE CREATION |
|---|
| | 662 | ///////////////////////////////////////////////// |
|---|
| | 663 | |
|---|
| | 664 | /** |
|---|
| | 665 | * Creates recipient headers. |
|---|
| | 666 | * @access private |
|---|
| | 667 | * @return string |
|---|
| | 668 | */ |
|---|
| | 669 | function AddrAppend($type, $addr) { |
|---|
| | 670 | $addr_str = $type . ': '; |
|---|
| | 671 | $addr_str .= $this->AddrFormat($addr[0]); |
|---|
| | 672 | if(count($addr) > 1) { |
|---|
| | 673 | for($i = 1; $i < count($addr); $i++) { |
|---|
| | 674 | $addr_str .= ', ' . $this->AddrFormat($addr[$i]); |
|---|
| | 675 | } |
|---|
| | 676 | } |
|---|
| | 677 | $addr_str .= $this->LE; |
|---|
| | 678 | |
|---|
| | 679 | return $addr_str; |
|---|
| | 680 | } |
|---|
| | 681 | |
|---|
| | 682 | /** |
|---|
| | 683 | * Formats an address correctly. |
|---|
| | 684 | * @access private |
|---|
| | 685 | * @return string |
|---|
| | 686 | */ |
|---|
| | 687 | function AddrFormat($addr) { |
|---|
| | 688 | if(empty($addr[1])) { |
|---|
| | 689 | $formatted = $this->SecureHeader($addr[0]); |
|---|
| | 690 | } else { |
|---|
| | 691 | $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|---|
| | 692 | } |
|---|
| | 693 | |
|---|
| | 694 | return $formatted; |
|---|
| | 695 | } |
|---|
| | 696 | |
|---|
| | 697 | /** |
|---|
| | 698 | * Wraps message for use with mailers that do not |
|---|
| | 699 | * automatically perform wrapping and for quoted-printable. |
|---|
| | 700 | * Original written by philippe. |
|---|
| | 701 | * @access private |
|---|
| | 702 | * @return string |
|---|
| | 703 | */ |
|---|
| | 704 | function WrapText($message, $length, $qp_mode = false) { |
|---|
| | 705 | $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|---|
| | 706 | // If utf-8 encoding is used, we will need to make sure we don't |
|---|
| | 707 | // split multibyte characters when we wrap |
|---|
| | 708 | $is_utf8 = (strtolower($this->CharSet) == "utf-8"); |
|---|
| | 709 | |
|---|
| | 710 | $message = $this->FixEOL($message); |
|---|
| | 711 | if (substr($message, -1) == $this->LE) { |
|---|
| | 712 | $message = substr($message, 0, -1); |
|---|
| | 713 | } |
|---|
| | 714 | |
|---|
| | 715 | $line = explode($this->LE, $message); |
|---|
| | 716 | $message = ''; |
|---|
| | 717 | for ($i=0 ;$i < count($line); $i++) { |
|---|
| | 718 | $line_part = explode(' ', $line[$i]); |
|---|
| | 719 | $buf = ''; |
|---|
| | 720 | for ($e = 0; $e<count($line_part); $e++) { |
|---|
| | 721 | $word = $line_part[$e]; |
|---|
| | 722 | if ($qp_mode and (strlen($word) > $length)) { |
|---|
| | 723 | $space_left = $length - strlen($buf) - 1; |
|---|
| | 724 | if ($e != 0) { |
|---|
| | 725 | if ($space_left > 20) { |
|---|
| | 726 | $len = $space_left; |
|---|
| | 727 | if ($is_utf8) { |
|---|
| | 728 | $len = $this->UTF8CharBoundary($word, $len); |
|---|
| | 729 | } elseif (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); |
|---|
| | 736 | $buf .= ' ' . $part; |
|---|
| | 737 | $message .= $buf . sprintf("=%s", $this->LE); |
|---|
| | 738 | } else { |
|---|
| | 739 | $message .= $buf . $soft_break; |
|---|
| | 740 | } |
|---|
| | 741 | $buf = ''; |
|---|
| | 742 | } |
|---|
| | 743 | while (strlen($word) > 0) { |
|---|
| | 744 | $len = $length; |
|---|
| | 745 | if ($is_utf8) { |
|---|
| | 746 | $len = $this->UTF8CharBoundary($word, $len); |
|---|
| | 747 | } elseif (substr($word, $len - 1, 1) == "=") { |
|---|
| | 748 | $len--; |
|---|
| | 749 | } elseif (substr($word, $len - 2, 1) == "=") { |
|---|
| | 750 | $len -= 2; |
|---|
| | 751 | } |
|---|
| | 752 | $part = substr($word, 0, $len); |
|---|
| | 753 | $word = substr($word, $len); |
|---|
| | 754 | |
|---|
| | 755 | if (strlen($word) > 0) { |
|---|
| | 756 | $message .= $part . sprintf("=%s", $this->LE); |
|---|
| | 757 | } else { |
|---|
| | 758 | $buf = $part; |
|---|
| | 759 | } |
|---|
| | 760 | } |
|---|
| | 761 | } else { |
|---|
| | 762 | $buf_o = $buf; |
|---|
| | 763 | $buf .= ($e == 0) ? $word : (' ' . $word); |
|---|
| | 764 | |
|---|
| | 765 | if (strlen($buf) > $length and $buf_o != '') { |
|---|
| | 766 | $message .= $buf_o . $soft_break; |
|---|
| | 767 | $buf = $word; |
|---|
| | 768 | } |
|---|