Changes in trunk/wp-includes/class-smtp.php [13425:17676]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-smtp.php
r13425 r17676 3 3 .---------------------------------------------------------------------------. 4 4 | Software: PHPMailer - PHP email class | 5 | Version: 2.0.4|5 | Version: 5.1 | 6 6 | Contact: via sourceforge.net support pages (also www.codeworxtech.com) | 7 7 | Info: http://phpmailer.sourceforge.net | 8 8 | Support: http://sourceforge.net/projects/phpmailer/ | 9 9 | ------------------------------------------------------------------------- | 10 | Author: Andy Prevost (project admininistrator) | 11 | Author: Brent R. Matzelle (original founder) | 12 | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. | 10 | Admin: Andy Prevost (project admininistrator) | 11 | Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net | 12 | : Marcus Bointon (coolbru) coolbru@users.sourceforge.net | 13 | Founder: Brent R. Matzelle (original founder) | 14 | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. | 13 15 | Copyright (c) 2001-2003, Brent R. Matzelle | 14 16 | ------------------------------------------------------------------------- | … … 24 26 | - Oursourcing (highly qualified programmers and graphic designers) | 25 27 '---------------------------------------------------------------------------' 28 */ 29 30 /** 31 * PHPMailer - PHP SMTP email transport class 32 * NOTE: Designed for use with PHP version 5 and up 33 * @package PHPMailer 34 * @author Andy Prevost 35 * @author Marcus Bointon 36 * @copyright 2004 - 2008 Andy Prevost 37 * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL) 38 * @version $Id: class.smtp.php 444 2009-05-05 11:22:26Z coolbru $ 26 39 */ 40 27 41 /** 28 42 * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP … … 30 44 * error. SMTP also provides some utility methods for sending mail 31 45 * to an SMTP server. 32 * @package PHPMailer 33 * @author Chris Ryan 46 * original author: Chris Ryan 34 47 */ 35 48 36 class SMTP 37 { 49 class SMTP { 38 50 /** 39 51 * SMTP server port 40 52 * @var int 41 53 */ 42 var$SMTP_PORT = 25;54 public $SMTP_PORT = 25; 43 55 44 56 /** … … 46 58 * @var string 47 59 */ 48 var$CRLF = "\r\n";60 public $CRLF = "\r\n"; 49 61 50 62 /** … … 52 64 * @var bool 53 65 */ 54 var $do_debug; #the level of debug to perform66 public $do_debug; // the level of debug to perform 55 67 56 68 /** … … 58 70 * @var bool 59 71 */ 60 var$do_verp = false;61 62 / **#@+63 * @access private64 */65 var $smtp_conn; # the socket to the server 66 var $error; # error if any on the last call67 var $helo_rply; # the reply the server sent to us for HELO68 /**#@-*/72 public $do_verp = false; 73 74 ///////////////////////////////////////////////// 75 // PROPERTIES, PRIVATE AND PROTECTED 76 ///////////////////////////////////////////////// 77 78 private $smtp_conn; // the socket to the server 79 private $error; // error if any on the last call 80 private $helo_rply; // the reply the server sent to us for HELO 69 81 70 82 /** … … 73 85 * @return void 74 86 */ 75 function SMTP() {87 public function __construct() { 76 88 $this->smtp_conn = 0; 77 89 $this->error = null; … … 81 93 } 82 94 83 / *************************************************************84 * CONNECTION FUNCTIONS *85 ***********************************************************/95 ///////////////////////////////////////////////// 96 // CONNECTION FUNCTIONS 97 ///////////////////////////////////////////////// 86 98 87 99 /** … … 98 110 * @return bool 99 111 */ 100 function Connect($host,$port=0,$tval=30) {101 #set the error val to null so there is no confusion112 public function Connect($host, $port = 0, $tval = 30) { 113 // set the error val to null so there is no confusion 102 114 $this->error = null; 103 115 104 #make sure we are __not__ connected116 // make sure we are __not__ connected 105 117 if($this->connected()) { 106 # ok we are connected! what should we do? 107 # for now we will just give an error saying we 108 # are already connected 118 // already connected, generate error 109 119 $this->error = array("error" => "Already connected to a server"); 110 120 return false; … … 115 125 } 116 126 117 #connect to the smtp server118 $this->smtp_conn = fsockopen($host, #the host of the server119 $port, #the port to use120 $errno, #error number if any121 $errstr, #error message if any122 $tval); #give up after ? secs123 #verify we connected properly127 // connect to the smtp server 128 $this->smtp_conn = @fsockopen($host, // the host of the server 129 $port, // the port to use 130 $errno, // error number if any 131 $errstr, // error message if any 132 $tval); // give up after ? secs 133 // verify we connected properly 124 134 if(empty($this->smtp_conn)) { 125 135 $this->error = array("error" => "Failed to connect to server", … … 127 137 "errstr" => $errstr); 128 138 if($this->do_debug >= 1) { 129 echo "SMTP -> ERROR: " . $this->error["error"] . 130 ": $errstr ($errno)" . $this->CRLF; 131 } 132 return false; 133 } 134 135 # sometimes the SMTP server takes a little longer to respond 136 # so we will give it a longer timeout for the first read 137 // Windows still does not have support for this timeout function 139 echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />'; 140 } 141 return false; 142 } 143 144 // SMTP server can take longer to respond, give longer timeout for first read 145 // Windows does not have support for this timeout function 138 146 if(substr(PHP_OS, 0, 3) != "WIN") 139 147 socket_set_timeout($this->smtp_conn, $tval, 0); 140 148 141 # get any announcement stuff149 // get any announcement 142 150 $announce = $this->get_lines(); 143 151 144 # set the timeout of any socket functions at 1/10 of a second 145 //if(function_exists("socket_set_timeout")) 146 // socket_set_timeout($this->smtp_conn, 0, 100000); 147 148 if($this->do_debug >= 2) { 149 echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce; 152 if($this->do_debug >= 2) { 153 echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />'; 154 } 155 156 return true; 157 } 158 159 /** 160 * Initiate a TLS communication with the server. 161 * 162 * SMTP CODE 220 Ready to start TLS 163 * SMTP CODE 501 Syntax error (no parameters allowed) 164 * SMTP CODE 454 TLS not available due to temporary reason 165 * @access public 166 * @return bool success 167 */ 168 public function StartTLS() { 169 $this->error = null; # to avoid confusion 170 171 if(!$this->connected()) { 172 $this->error = array("error" => "Called StartTLS() without being connected"); 173 return false; 174 } 175 176 fputs($this->smtp_conn,"STARTTLS" . $this->CRLF); 177 178 $rply = $this->get_lines(); 179 $code = substr($rply,0,3); 180 181 if($this->do_debug >= 2) { 182 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; 183 } 184 185 if($code != 220) { 186 $this->error = 187 array("error" => "STARTTLS not accepted from server", 188 "smtp_code" => $code, 189 "smtp_msg" => substr($rply,4)); 190 if($this->do_debug >= 1) { 191 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 192 } 193 return false; 194 } 195 196 // Begin encrypted connection 197 if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { 198 return false; 150 199 } 151 200 … … 159 208 * @return bool 160 209 */ 161 function Authenticate($username, $password) {210 public function Authenticate($username, $password) { 162 211 // Start authentication 163 212 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); … … 172 221 "smtp_msg" => substr($rply,4)); 173 222 if($this->do_debug >= 1) { 174 echo "SMTP -> ERROR: " . $this->error["error"] . 175 ": " . $rply . $this->CRLF; 223 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 176 224 } 177 225 return false; … … 190 238 "smtp_msg" => substr($rply,4)); 191 239 if($this->do_debug >= 1) { 192 echo "SMTP -> ERROR: " . $this->error["error"] . 193 ": " . $rply . $this->CRLF; 240 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 194 241 } 195 242 return false; … … 208 255 "smtp_msg" => substr($rply,4)); 209 256 if($this->do_debug >= 1) { 210 echo "SMTP -> ERROR: " . $this->error["error"] . 211 ": " . $rply . $this->CRLF; 257 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 212 258 } 213 259 return false; … … 219 265 /** 220 266 * Returns true if connected to a server otherwise false 221 * @access p rivate222 * @return bool 223 */ 224 function Connected() {267 * @access public 268 * @return bool 269 */ 270 public function Connected() { 225 271 if(!empty($this->smtp_conn)) { 226 272 $sock_status = socket_get_status($this->smtp_conn); 227 273 if($sock_status["eof"]) { 228 # hmm this is an odd situation... the socket is 229 # valid but we are not connected anymore 274 // the socket is valid but we are not connected 230 275 if($this->do_debug >= 1) { 231 echo "SMTP -> NOTICE:" . $this->CRLF . 232 "EOF caught while checking if connected"; 276 echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"; 233 277 } 234 278 $this->Close(); 235 279 return false; 236 280 } 237 return true; #everything looks good281 return true; // everything looks good 238 282 } 239 283 return false; … … 247 291 * @return void 248 292 */ 249 function Close() {250 $this->error = null; #so there is no confusion293 public function Close() { 294 $this->error = null; // so there is no confusion 251 295 $this->helo_rply = null; 252 296 if(!empty($this->smtp_conn)) { 253 #close the connection and cleanup297 // close the connection and cleanup 254 298 fclose($this->smtp_conn); 255 299 $this->smtp_conn = 0; … … 257 301 } 258 302 259 / ***************************************************************260 * SMTP COMMANDS *261 *************************************************************/303 ///////////////////////////////////////////////// 304 // SMTP COMMANDS 305 ///////////////////////////////////////////////// 262 306 263 307 /** … … 266 310 * that is to be send with the headers. Each header needs to be 267 311 * on a single line followed by a <CRLF> with the message headers 268 * and the message body being sep arated by and additional <CRLF>.312 * and the message body being seperated by and additional <CRLF>. 269 313 * 270 314 * Implements rfc 821: DATA <CRLF> … … 280 324 * @return bool 281 325 */ 282 function Data($msg_data) {283 $this->error = null; #so no confusion is caused326 public function Data($msg_data) { 327 $this->error = null; // so no confusion is caused 284 328 285 329 if(!$this->connected()) { … … 295 339 296 340 if($this->do_debug >= 2) { 297 echo "SMTP -> FROM SERVER:" . $ this->CRLF . $rply;341 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; 298 342 } 299 343 … … 304 348 "smtp_msg" => substr($rply,4)); 305 349 if($this->do_debug >= 1) { 306 echo "SMTP -> ERROR: " . $this->error["error"] . 307 ": " . $rply . $this->CRLF;308 }309 return false;310 } 311 312 # the server is ready to accept data!313 # according to rfc 821 we should not send more than 1000314 # including the CRLF315 # characters on a single line so we will break the data up316 # into lines by \r and/or \n then if needed we will break317 # each of those into smaller lines to fit within the limit.318 # in addition we will be looking for lines that start with319 # a period '.' and append and additional period '.' to that320 # line. NOTE: this does not count towards are limit.321 322 #normalize the line breaks so we know the explode works350 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 351 } 352 return false; 353 } 354 355 /* the server is ready to accept data! 356 * according to rfc 821 we should not send more than 1000 357 * including the CRLF 358 * characters on a single line so we will break the data up 359 * into lines by \r and/or \n then if needed we will break 360 * each of those into smaller lines to fit within the limit. 361 * in addition we will be looking for lines that start with 362 * a period '.' and append and additional period '.' to that 363 * line. NOTE: this does not count towards limit. 364 */ 365 366 // normalize the line breaks so we know the explode works 323 367 $msg_data = str_replace("\r\n","\n",$msg_data); 324 368 $msg_data = str_replace("\r","\n",$msg_data); 325 369 $lines = explode("\n",$msg_data); 326 370 327 # we need to find a good way to determine is headers are 328 # in the msg_data or if it is a straight msg body 329 # currently I am assuming rfc 822 definitions of msg headers 330 # and if the first field of the first line (':' sperated) 331 # does not contain a space then it _should_ be a header 332 # and we can process all lines before a blank "" line as 333 # headers. 371 /* we need to find a good way to determine is headers are 372 * in the msg_data or if it is a straight msg body 373 * currently I am assuming rfc 822 definitions of msg headers 374 * and if the first field of the first line (':' sperated) 375 * does not contain a space then it _should_ be a header 376 * and we can process all lines before a blank "" line as 377 * headers. 378 */ 379 334 380 $field = substr($lines[0],0,strpos($lines[0],":")); 335 381 $in_headers = false; … … 338 384 } 339 385 340 $max_line_length = 998; #used below; set here for ease in change386 $max_line_length = 998; // used below; set here for ease in change 341 387 342 388 while(list(,$line) = @each($lines)) { … … 345 391 $in_headers = false; 346 392 } 347 # ok we need to break this line up into several 348 # smaller lines 393 // ok we need to break this line up into several smaller lines 349 394 while(strlen($line) > $max_line_length) { 350 395 $pos = strrpos(substr($line,0,$max_line_length)," "); 351 396 352 #Patch to fix DOS attack397 // Patch to fix DOS attack 353 398 if(!$pos) { 354 399 $pos = $max_line_length - 1; 400 $lines_out[] = substr($line,0,$pos); 401 $line = substr($line,$pos); 402 } else { 403 $lines_out[] = substr($line,0,$pos); 404 $line = substr($line,$pos + 1); 355 405 } 356 406 357 $lines_out[] = substr($line,0,$pos); 358 $line = substr($line,$pos + 1); 359 # if we are processing headers we need to 360 # add a LWSP-char to the front of the new line 361 # rfc 822 on long msg headers 407 /* if processing headers add a LWSP-char to the front of new line 408 * rfc 822 on long msg headers 409 */ 362 410 if($in_headers) { 363 411 $line = "\t" . $line; … … 366 414 $lines_out[] = $line; 367 415 368 # nowsend the lines to the server416 // send the lines to the server 369 417 while(list(,$line_out) = @each($lines_out)) { 370 418 if(strlen($line_out) > 0) … … 378 426 } 379 427 380 # ok all the message data has been sent so lets get this 381 # over with aleady 428 // message data has been sent 382 429 fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); 383 430 … … 386 433 387 434 if($this->do_debug >= 2) { 388 echo "SMTP -> FROM SERVER:" . $ this->CRLF . $rply;435 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; 389 436 } 390 437 … … 395 442 "smtp_msg" => substr($rply,4)); 396 443 if($this->do_debug >= 1) { 397 echo "SMTP -> ERROR: " . $this->error["error"] . 398 ": " . $rply . $this->CRLF; 399 } 400 return false; 401 } 402 return true; 403 } 404 405 /** 406 * Expand takes the name and asks the server to list all the 407 * people who are members of the _list_. Expand will return 408 * back and array of the result or false if an error occurs. 409 * Each value in the array returned has the format of: 410 * [ <full-name> <sp> ] <path> 411 * The definition of <path> is defined in rfc 821 412 * 413 * Implements rfc 821: EXPN <SP> <string> <CRLF> 414 * 415 * SMTP CODE SUCCESS: 250 416 * SMTP CODE FAILURE: 550 417 * SMTP CODE ERROR : 500,501,502,504,421 418 * @access public 419 * @return string array 420 */ 421 function Expand($name) { 422 $this->error = null; # so no confusion is caused 423 424 if(!$this->connected()) { 425 $this->error = array( 426 "error" => "Called Expand() without being connected"); 427 return false; 428 } 429 430 fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF); 431 432 $rply = $this->get_lines(); 433 $code = substr($rply,0,3); 434 435 if($this->do_debug >= 2) { 436 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 437 } 438 439 if($code != 250) { 440 $this->error = 441 array("error" => "EXPN not accepted from server", 442 "smtp_code" => $code, 443 "smtp_msg" => substr($rply,4)); 444 if($this->do_debug >= 1) { 445 echo "SMTP -> ERROR: " . $this->error["error"] . 446 ": " . $rply . $this->CRLF; 447 } 448 return false; 449 } 450 451 # parse the reply and place in our array to return to user 452 $entries = explode($this->CRLF,$rply); 453 while(list(,$l) = @each($entries)) { 454 $list[] = substr($l,4); 455 } 456 457 return $list; 444 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 445 } 446 return false; 447 } 448 return true; 458 449 } 459 450 … … 470 461 * @return bool 471 462 */ 472 function Hello($host="") {473 $this->error = null; #so no confusion is caused463 public function Hello($host = '') { 464 $this->error = null; // so no confusion is caused 474 465 475 466 if(!$this->connected()) { … … 479 470 } 480 471 481 # if a hostname for the HELO was not specified determine 482 # a suitable one to send 472 // if hostname for HELO was not specified send default 483 473 if(empty($host)) { 484 # we need to determine some sort of appopiate default 485 # to send to the server 474 // determine appropriate default to send to server 486 475 $host = "localhost"; 487 476 } 488 477 489 478 // Send extended hello first (RFC 2821) 490 if(!$this->SendHello("EHLO", $host)) 491 {492 if(!$this->SendHello("HELO", $host))493 return false;479 if(!$this->SendHello("EHLO", $host)) { 480 if(!$this->SendHello("HELO", $host)) { 481 return false; 482 } 494 483 } 495 484 … … 502 491 * @return bool 503 492 */ 504 function SendHello($hello, $host) {493 private function SendHello($hello, $host) { 505 494 fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); 506 495 … … 509 498 510 499 if($this->do_debug >= 2) { 511 echo "SMTP -> FROM SERVER: " . $ this->CRLF . $rply;500 echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'; 512 501 } 513 502 … … 518 507 "smtp_msg" => substr($rply,4)); 519 508 if($this->do_debug >= 1) { 520 echo "SMTP -> ERROR: " . $this->error["error"] . 521 ": " . $rply . $this->CRLF; 509 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 522 510 } 523 511 return false; … … 527 515 528 516 return true; 529 }530 531 /**532 * Gets help information on the keyword specified. If the keyword533 * is not specified then returns generic help, ussually contianing534 * A list of keywords that help is available on. This function535 * returns the results back to the user. It is up to the user to536 * handle the returned data. If an error occurs then false is537 * returned with $this->error set appropiately.538 *539 * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>540 *541 * SMTP CODE SUCCESS: 211,214542 * SMTP CODE ERROR : 500,501,502,504,421543 * @access public544 * @return string545 */546 function Help($keyword="") {547 $this->error = null; # to avoid confusion548 549 if(!$this->connected()) {550 $this->error = array(551 "error" => "Called Help() without being connected");552 return false;553 }554 555 $extra = "";556 if(!empty($keyword)) {557 $extra = " " . $keyword;558 }559 560 fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);561 562 $rply = $this->get_lines();563 $code = substr($rply,0,3);564 565 if($this->do_debug >= 2) {566 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;567 }568 569 if($code != 211 && $code != 214) {570 $this->error =571 array("error" => "HELP not accepted from server",572 "smtp_code" => $code,573 "smtp_msg" => substr($rply,4));574 if($this->do_debug >= 1) {575 echo "SMTP -> ERROR: " . $this->error["error"] .576 ": " . $rply . $this->CRLF;577 }578 return false;579 }580 581 return $rply;582 517 } 583 518 … … 596 531 * @return bool 597 532 */ 598 function Mail($from) {599 $this->error = null; #so no confusion is caused533 public function Mail($from) { 534 $this->error = null; // so no confusion is caused 600 535 601 536 if(!$this->connected()) { … … 612 547 613 548 if($this->do_debug >= 2) { 614 echo "SMTP -> FROM SERVER:" . $ this->CRLF . $rply;549 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; 615 550 } 616 551 … … 621 556 "smtp_msg" => substr($rply,4)); 622 557 if($this->do_debug >= 1) { 623 echo "SMTP -> ERROR: " . $this->error["error"] . 624 ": " . $rply . $this->CRLF; 625 } 626 return false; 627 } 628 return true; 629 } 630 631 /** 632 * Sends the command NOOP to the SMTP server. 633 * 634 * Implements from rfc 821: NOOP <CRLF> 635 * 636 * SMTP CODE SUCCESS: 250 637 * SMTP CODE ERROR : 500, 421 638 * @access public 639 * @return bool 640 */ 641 function Noop() { 642 $this->error = null; # so no confusion is caused 643 644 if(!$this->connected()) { 645 $this->error = array( 646 "error" => "Called Noop() without being connected"); 647 return false; 648 } 649 650 fputs($this->smtp_conn,"NOOP" . $this->CRLF); 651 652 $rply = $this->get_lines(); 653 $code = substr($rply,0,3); 654 655 if($this->do_debug >= 2) { 656 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 657 } 658 659 if($code != 250) { 660 $this->error = 661 array("error" => "NOOP not accepted from server", 662 "smtp_code" => $code, 663 "smtp_msg" => substr($rply,4)); 664 if($this->do_debug >= 1) { 665 echo "SMTP -> ERROR: " . $this->error["error"] . 666 ": " . $rply . $this->CRLF; 558 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 667 559 } 668 560 return false; … … 682 574 * @return bool 683 575 */ 684 function Quit($close_on_error=true) {685 $this->error = null; #so there is no confusion576 public function Quit($close_on_error = true) { 577 $this->error = null; // so there is no confusion 686 578 687 579 if(!$this->connected()) { … … 691 583 } 692 584 693 #send the quit command to the server585 // send the quit command to the server 694 586 fputs($this->smtp_conn,"quit" . $this->CRLF); 695 587 696 #get any good-bye messages588 // get any good-bye messages 697 589 $byemsg = $this->get_lines(); 698 590 699 591 if($this->do_debug >= 2) { 700 echo "SMTP -> FROM SERVER:" . $ this->CRLF . $byemsg;592 echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'; 701 593 } 702 594 … … 706 598 $code = substr($byemsg,0,3); 707 599 if($code != 221) { 708 #use e as a tmp var cause Close will overwrite $this->error600 // use e as a tmp var cause Close will overwrite $this->error 709 601 $e = array("error" => "SMTP server rejected quit command", 710 602 "smtp_code" => $code, … … 712 604 $rval = false; 713 605 if($this->do_debug >= 1) { 714 echo "SMTP -> ERROR: " . $e["error"] . ": " . 715 $byemsg . $this->CRLF; 606 echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'; 716 607 } 717 608 } … … 736 627 * @return bool 737 628 */ 738 function Recipient($to) {739 $this->error = null; #so no confusion is caused629 public function Recipient($to) { 630 $this->error = null; // so no confusion is caused 740 631 741 632 if(!$this->connected()) { … … 751 642 752 643 if($this->do_debug >= 2) { 753 echo "SMTP -> FROM SERVER:" . $ this->CRLF . $rply;644 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; 754 645 } 755 646 … … 760 651 "smtp_msg" => substr($rply,4)); 761 652 if($this->do_debug >= 1) { 762 echo "SMTP -> ERROR: " . $this->error["error"] . 763 ": " . $rply . $this->CRLF; 653 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 764 654 } 765 655 return false; … … 780 670 * @return bool 781 671 */ 782 function Reset() {783 $this->error = null; #so no confusion is caused672 public function Reset() { 673 $this->error = null; // so no confusion is caused 784 674 785 675 if(!$this->connected()) { … … 795 685 796 686 if($this->do_debug >= 2) { 797 echo "SMTP -> FROM SERVER:" . $ this->CRLF . $rply;687 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; 798 688 } 799 689 … … 804 694 "smtp_msg" => substr($rply,4)); 805 695 if($this->do_debug >= 1) { 806 echo "SMTP -> ERROR: " . $this->error["error"] . 807 ": " . $rply . $this->CRLF; 808 } 809 return false; 810 } 811 812 return true; 813 } 814 815 /** 816 * Starts a mail transaction from the email address specified in 817 * $from. Returns true if successful or false otherwise. If True 818 * the mail transaction is started and then one or more Recipient 819 * commands may be called followed by a Data command. This command 820 * will send the message to the users terminal if they are logged 821 * in. 822 * 823 * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF> 824 * 825 * SMTP CODE SUCCESS: 250 826 * SMTP CODE SUCCESS: 552,451,452 827 * SMTP CODE SUCCESS: 500,501,502,421 828 * @access public 829 * @return bool 830 */ 831 function Send($from) { 832 $this->error = null; # so no confusion is caused 833 834 if(!$this->connected()) { 835 $this->error = array( 836 "error" => "Called Send() without being connected"); 837 return false; 838 } 839 840 fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF); 841 842 $rply = $this->get_lines(); 843 $code = substr($rply,0,3); 844 845 if($this->do_debug >= 2) { 846 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 847 } 848 849 if($code != 250) { 850 $this->error = 851 array("error" => "SEND not accepted from server", 852 "smtp_code" => $code, 853 "smtp_msg" => substr($rply,4)); 854 if($this->do_debug >= 1) { 855 echo "SMTP -> ERROR: " . $this->error["error"] . 856 ": " . $rply . $this->CRLF; 857 } 858 return false; 859 } 696 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 697 } 698 return false; 699 } 700 860 701 return true; 861 702 } … … 877 718 * @return bool 878 719 */ 879 function SendAndMail($from) {880 $this->error = null; #so no confusion is caused720 public function SendAndMail($from) { 721 $this->error = null; // so no confusion is caused 881 722 882 723 if(!$this->connected()) { … … 892 733 893 734 if($this->do_debug >= 2) { 894 echo "SMTP -> FROM SERVER:" . $ this->CRLF . $rply;735 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; 895 736 } 896 737 … … 901 742 "smtp_msg" => substr($rply,4)); 902 743 if($this->do_debug >= 1) { 903 echo "SMTP -> ERROR: " . $this->error["error"] . 904 ": " . $rply . $this->CRLF; 905 } 906 return false; 907 } 908 return true; 909 } 910 911 /** 912 * Starts a mail transaction from the email address specified in 913 * $from. Returns true if successful or false otherwise. If True 914 * the mail transaction is started and then one or more Recipient 915 * commands may be called followed by a Data command. This command 916 * will send the message to the users terminal if they are logged 917 * in or mail it to them if they are not. 918 * 919 * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF> 920 * 921 * SMTP CODE SUCCESS: 250 922 * SMTP CODE SUCCESS: 552,451,452 923 * SMTP CODE SUCCESS: 500,501,502,421 924 * @access public 925 * @return bool 926 */ 927 function SendOrMail($from) { 928 $this->error = null; # so no confusion is caused 929 930 if(!$this->connected()) { 931 $this->error = array( 932 "error" => "Called SendOrMail() without being connected"); 933 return false; 934 } 935 936 fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF); 937 938 $rply = $this->get_lines(); 939 $code = substr($rply,0,3); 940 941 if($this->do_debug >= 2) { 942 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 943 } 944 945 if($code != 250) { 946 $this->error = 947 array("error" => "SOML not accepted from server", 948 "smtp_code" => $code, 949 "smtp_msg" => substr($rply,4)); 950 if($this->do_debug >= 1) { 951 echo "SMTP -> ERROR: " . $this->error["error"] . 952 ": " . $rply . $this->CRLF; 744 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 953 745 } 954 746 return false; … … 970 762 * @return bool 971 763 */ 972 function Turn() {764 public function Turn() { 973 765 $this->error = array("error" => "This method, TURN, of the SMTP ". 974 766 "is not implemented"); 975 767 if($this->do_debug >= 1) { 976 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF ;768 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'; 977 769 } 978 770 return false; … … 980 772 981 773 /** 982 * Verifies that the name is recognized by the server. 983 * Returns false if the name could not be verified otherwise 984 * the response from the server is returned. 985 * 986 * Implements rfc 821: VRFY <SP> <string> <CRLF> 987 * 988 * SMTP CODE SUCCESS: 250,251 989 * SMTP CODE FAILURE: 550,551,553 990 * SMTP CODE ERROR : 500,501,502,421 991 * @access public 992 * @return int 993 */ 994 function Verify($name) { 995 $this->error = null; # so no confusion is caused 996 997 if(!$this->connected()) { 998 $this->error = array( 999 "error" => "Called Verify() without being connected"); 1000 return false; 1001 } 1002 1003 fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF); 1004 1005 $rply = $this->get_lines(); 1006 $code = substr($rply,0,3); 1007 1008 if($this->do_debug >= 2) { 1009 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 1010 } 1011 1012 if($code != 250 && $code != 251) { 1013 $this->error = 1014 array("error" => "VRFY failed on name '$name'", 1015 "smtp_code" => $code, 1016 "smtp_msg" => substr($rply,4)); 1017 if($this->do_debug >= 1) { 1018 echo "SMTP -> ERROR: " . $this->error["error"] . 1019 ": " . $rply . $this->CRLF; 1020 } 1021 return false; 1022 } 1023 return $rply; 1024 } 1025 1026 /******************************************************************* 1027 * INTERNAL FUNCTIONS * 1028 ******************************************************************/ 774 * Get the current error 775 * @access public 776 * @return array 777 */ 778 public function getError() { 779 return $this->error; 780 } 781 782 ///////////////////////////////////////////////// 783 // INTERNAL FUNCTIONS 784 ///////////////////////////////////////////////// 1029 785 1030 786 /** … … 1037 793 * @return string 1038 794 */ 1039 function get_lines() {795 private function get_lines() { 1040 796 $data = ""; 1041 797 while($str = @fgets($this->smtp_conn,515)) { 1042 798 if($this->do_debug >= 4) { 1043 echo "SMTP -> get_lines(): \$data was \"$data\"" . 1044 $this->CRLF; 1045 echo "SMTP -> get_lines(): \$str is \"$str\"" . 1046 $this->CRLF; 799 echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'; 800 echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'; 1047 801 } 1048 802 $data .= $str; 1049 803 if($this->do_debug >= 4) { 1050 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF; 1051 } 1052 # if the 4th character is a space then we are done reading 1053 # so just break the loop 804 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'; 805 } 806 // if 4th character is a space, we are done reading, break the loop 1054 807 if(substr($str,3,1) == " ") { break; } 1055 808 } … … 1059 812 } 1060 813 1061 1062 ?> 814 ?>
Note: See TracChangeset
for help on using the changeset viewer.