Changes in trunk/wp-includes/class-smtp.php [17676:13425]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-smtp.php
r17676 r13425 3 3 .---------------------------------------------------------------------------. 4 4 | Software: PHPMailer - PHP email class | 5 | Version: 5.1|5 | Version: 2.0.4 | 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 | 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. | 10 | Author: Andy Prevost (project admininistrator) | 11 | Author: Brent R. Matzelle (original founder) | 12 | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. | 15 13 | Copyright (c) 2001-2003, Brent R. Matzelle | 16 14 | ------------------------------------------------------------------------- | … … 26 24 | - Oursourcing (highly qualified programmers and graphic designers) | 27 25 '---------------------------------------------------------------------------' 28 */29 30 /**31 * PHPMailer - PHP SMTP email transport class32 * NOTE: Designed for use with PHP version 5 and up33 * @package PHPMailer34 * @author Andy Prevost35 * @author Marcus Bointon36 * @copyright 2004 - 2008 Andy Prevost37 * @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 $39 26 */ 40 41 27 /** 42 28 * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP … … 44 30 * error. SMTP also provides some utility methods for sending mail 45 31 * to an SMTP server. 46 * original author: Chris Ryan 32 * @package PHPMailer 33 * @author Chris Ryan 47 34 */ 48 35 49 class SMTP { 36 class SMTP 37 { 50 38 /** 51 39 * SMTP server port 52 40 * @var int 53 41 */ 54 public$SMTP_PORT = 25;42 var $SMTP_PORT = 25; 55 43 56 44 /** … … 58 46 * @var string 59 47 */ 60 public$CRLF = "\r\n";48 var $CRLF = "\r\n"; 61 49 62 50 /** … … 64 52 * @var bool 65 53 */ 66 public $do_debug; //the level of debug to perform54 var $do_debug; # the level of debug to perform 67 55 68 56 /** … … 70 58 * @var bool 71 59 */ 72 public$do_verp = false;73 74 / ////////////////////////////////////////////////75 // PROPERTIES, PRIVATE AND PROTECTED76 /////////////////////////////////////////////////77 78 private $smtp_conn; // the socket to the server79 private $error; // error if any on the last call80 private $helo_rply; // the reply the server sent to us for HELO60 var $do_verp = false; 61 62 /**#@+ 63 * @access private 64 */ 65 var $smtp_conn; # the socket to the server 66 var $error; # error if any on the last call 67 var $helo_rply; # the reply the server sent to us for HELO 68 /**#@-*/ 81 69 82 70 /** … … 85 73 * @return void 86 74 */ 87 public function __construct() {75 function SMTP() { 88 76 $this->smtp_conn = 0; 89 77 $this->error = null; … … 93 81 } 94 82 95 / ////////////////////////////////////////////////96 // CONNECTION FUNCTIONS97 /////////////////////////////////////////////////83 /************************************************************* 84 * CONNECTION FUNCTIONS * 85 ***********************************************************/ 98 86 99 87 /** … … 110 98 * @return bool 111 99 */ 112 public function Connect($host, $port = 0, $tval =30) {113 //set the error val to null so there is no confusion100 function Connect($host,$port=0,$tval=30) { 101 # set the error val to null so there is no confusion 114 102 $this->error = null; 115 103 116 //make sure we are __not__ connected104 # make sure we are __not__ connected 117 105 if($this->connected()) { 118 // already connected, generate error 106 # ok we are connected! what should we do? 107 # for now we will just give an error saying we 108 # are already connected 119 109 $this->error = array("error" => "Already connected to a server"); 120 110 return false; … … 125 115 } 126 116 127 //connect to the smtp server128 $this->smtp_conn = @fsockopen($host, //the host of the server129 $port, //the port to use130 $errno, //error number if any131 $errstr, //error message if any132 $tval); //give up after ? secs133 //verify we connected properly117 #connect to the smtp server 118 $this->smtp_conn = fsockopen($host, # the host of the server 119 $port, # the port to use 120 $errno, # error number if any 121 $errstr, # error message if any 122 $tval); # give up after ? secs 123 # verify we connected properly 134 124 if(empty($this->smtp_conn)) { 135 125 $this->error = array("error" => "Failed to connect to server", … … 137 127 "errstr" => $errstr); 138 128 if($this->do_debug >= 1) { 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 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 146 138 if(substr(PHP_OS, 0, 3) != "WIN") 147 139 socket_set_timeout($this->smtp_conn, $tval, 0); 148 140 149 // get any announcement141 # get any announcement stuff 150 142 $announce = $this->get_lines(); 151 143 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; 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; 199 150 } 200 151 … … 208 159 * @return bool 209 160 */ 210 publicfunction Authenticate($username, $password) {161 function Authenticate($username, $password) { 211 162 // Start authentication 212 163 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); … … 221 172 "smtp_msg" => substr($rply,4)); 222 173 if($this->do_debug >= 1) { 223 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 174 echo "SMTP -> ERROR: " . $this->error["error"] . 175 ": " . $rply . $this->CRLF; 224 176 } 225 177 return false; … … 238 190 "smtp_msg" => substr($rply,4)); 239 191 if($this->do_debug >= 1) { 240 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 192 echo "SMTP -> ERROR: " . $this->error["error"] . 193 ": " . $rply . $this->CRLF; 241 194 } 242 195 return false; … … 255 208 "smtp_msg" => substr($rply,4)); 256 209 if($this->do_debug >= 1) { 257 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 210 echo "SMTP -> ERROR: " . $this->error["error"] . 211 ": " . $rply . $this->CRLF; 258 212 } 259 213 return false; … … 265 219 /** 266 220 * Returns true if connected to a server otherwise false 267 * @access p ublic268 * @return bool 269 */ 270 publicfunction Connected() {221 * @access private 222 * @return bool 223 */ 224 function Connected() { 271 225 if(!empty($this->smtp_conn)) { 272 226 $sock_status = socket_get_status($this->smtp_conn); 273 227 if($sock_status["eof"]) { 274 // the socket is valid but we are not connected 228 # hmm this is an odd situation... the socket is 229 # valid but we are not connected anymore 275 230 if($this->do_debug >= 1) { 276 echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"; 231 echo "SMTP -> NOTICE:" . $this->CRLF . 232 "EOF caught while checking if connected"; 277 233 } 278 234 $this->Close(); 279 235 return false; 280 236 } 281 return true; //everything looks good237 return true; # everything looks good 282 238 } 283 239 return false; … … 291 247 * @return void 292 248 */ 293 publicfunction Close() {294 $this->error = null; //so there is no confusion249 function Close() { 250 $this->error = null; # so there is no confusion 295 251 $this->helo_rply = null; 296 252 if(!empty($this->smtp_conn)) { 297 //close the connection and cleanup253 # close the connection and cleanup 298 254 fclose($this->smtp_conn); 299 255 $this->smtp_conn = 0; … … 301 257 } 302 258 303 / ////////////////////////////////////////////////304 // SMTP COMMANDS305 /////////////////////////////////////////////////259 /*************************************************************** 260 * SMTP COMMANDS * 261 *************************************************************/ 306 262 307 263 /** … … 310 266 * that is to be send with the headers. Each header needs to be 311 267 * on a single line followed by a <CRLF> with the message headers 312 * and the message body being sep erated by and additional <CRLF>.268 * and the message body being separated by and additional <CRLF>. 313 269 * 314 270 * Implements rfc 821: DATA <CRLF> … … 324 280 * @return bool 325 281 */ 326 publicfunction Data($msg_data) {327 $this->error = null; //so no confusion is caused282 function Data($msg_data) { 283 $this->error = null; # so no confusion is caused 328 284 329 285 if(!$this->connected()) { … … 339 295 340 296 if($this->do_debug >= 2) { 341 echo "SMTP -> FROM SERVER:" . $ rply . $this->CRLF . '<br />';297 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 342 298 } 343 299 … … 348 304 "smtp_msg" => substr($rply,4)); 349 305 if($this->do_debug >= 1) { 350 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 1000357 * including the CRLF358 * characters on a single line so we will break the data up359 * into lines by \r and/or \n then if needed we will break360 * each of those into smaller lines to fit within the limit.361 * in addition we will be looking for lines that start with362 * a period '.' and append and additional period '.' to that363 * line. NOTE: this does not count towards limit.364 */365 366 //normalize the line breaks so we know the explode works306 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 1000 314 # including the CRLF 315 # characters on a single line so we will break the data up 316 # into lines by \r and/or \n then if needed we will break 317 # each of those into smaller lines to fit within the limit. 318 # in addition we will be looking for lines that start with 319 # a period '.' and append and additional period '.' to that 320 # line. NOTE: this does not count towards are limit. 321 322 # normalize the line breaks so we know the explode works 367 323 $msg_data = str_replace("\r\n","\n",$msg_data); 368 324 $msg_data = str_replace("\r","\n",$msg_data); 369 325 $lines = explode("\n",$msg_data); 370 326 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 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. 380 334 $field = substr($lines[0],0,strpos($lines[0],":")); 381 335 $in_headers = false; … … 384 338 } 385 339 386 $max_line_length = 998; //used below; set here for ease in change340 $max_line_length = 998; # used below; set here for ease in change 387 341 388 342 while(list(,$line) = @each($lines)) { … … 391 345 $in_headers = false; 392 346 } 393 // ok we need to break this line up into several smaller lines 347 # ok we need to break this line up into several 348 # smaller lines 394 349 while(strlen($line) > $max_line_length) { 395 350 $pos = strrpos(substr($line,0,$max_line_length)," "); 396 351 397 //Patch to fix DOS attack352 # Patch to fix DOS attack 398 353 if(!$pos) { 399 354 $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);405 355 } 406 356 407 /* if processing headers add a LWSP-char to the front of new line 408 * rfc 822 on long msg headers 409 */ 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 410 362 if($in_headers) { 411 363 $line = "\t" . $line; … … 414 366 $lines_out[] = $line; 415 367 416 //send the lines to the server368 # now send the lines to the server 417 369 while(list(,$line_out) = @each($lines_out)) { 418 370 if(strlen($line_out) > 0) … … 426 378 } 427 379 428 // message data has been sent 380 # ok all the message data has been sent so lets get this 381 # over with aleady 429 382 fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); 430 383 … … 433 386 434 387 if($this->do_debug >= 2) { 435 echo "SMTP -> FROM SERVER:" . $ rply . $this->CRLF . '<br />';388 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 436 389 } 437 390 … … 442 395 "smtp_msg" => substr($rply,4)); 443 396 if($this->do_debug >= 1) { 444 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 445 } 446 return false; 447 } 448 return true; 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; 449 458 } 450 459 … … 461 470 * @return bool 462 471 */ 463 public function Hello($host = '') {464 $this->error = null; //so no confusion is caused472 function Hello($host="") { 473 $this->error = null; # so no confusion is caused 465 474 466 475 if(!$this->connected()) { … … 470 479 } 471 480 472 // if hostname for HELO was not specified send default 481 # if a hostname for the HELO was not specified determine 482 # a suitable one to send 473 483 if(empty($host)) { 474 // determine appropriate default to send to server 484 # we need to determine some sort of appopiate default 485 # to send to the server 475 486 $host = "localhost"; 476 487 } 477 488 478 489 // Send extended hello first (RFC 2821) 479 if(!$this->SendHello("EHLO", $host)) {480 if(!$this->SendHello("HELO", $host)){481 return false;482 }490 if(!$this->SendHello("EHLO", $host)) 491 { 492 if(!$this->SendHello("HELO", $host)) 493 return false; 483 494 } 484 495 … … 491 502 * @return bool 492 503 */ 493 privatefunction SendHello($hello, $host) {504 function SendHello($hello, $host) { 494 505 fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); 495 506 … … 498 509 499 510 if($this->do_debug >= 2) { 500 echo "SMTP -> FROM SERVER: " . $ rply . $this->CRLF . '<br />';511 echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply; 501 512 } 502 513 … … 507 518 "smtp_msg" => substr($rply,4)); 508 519 if($this->do_debug >= 1) { 509 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 520 echo "SMTP -> ERROR: " . $this->error["error"] . 521 ": " . $rply . $this->CRLF; 510 522 } 511 523 return false; … … 515 527 516 528 return true; 529 } 530 531 /** 532 * Gets help information on the keyword specified. If the keyword 533 * is not specified then returns generic help, ussually contianing 534 * A list of keywords that help is available on. This function 535 * returns the results back to the user. It is up to the user to 536 * handle the returned data. If an error occurs then false is 537 * returned with $this->error set appropiately. 538 * 539 * Implements rfc 821: HELP [ <SP> <string> ] <CRLF> 540 * 541 * SMTP CODE SUCCESS: 211,214 542 * SMTP CODE ERROR : 500,501,502,504,421 543 * @access public 544 * @return string 545 */ 546 function Help($keyword="") { 547 $this->error = null; # to avoid confusion 548 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; 517 582 } 518 583 … … 531 596 * @return bool 532 597 */ 533 publicfunction Mail($from) {534 $this->error = null; //so no confusion is caused598 function Mail($from) { 599 $this->error = null; # so no confusion is caused 535 600 536 601 if(!$this->connected()) { … … 547 612 548 613 if($this->do_debug >= 2) { 549 echo "SMTP -> FROM SERVER:" . $ rply . $this->CRLF . '<br />';614 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 550 615 } 551 616 … … 556 621 "smtp_msg" => substr($rply,4)); 557 622 if($this->do_debug >= 1) { 558 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 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; 559 667 } 560 668 return false; … … 574 682 * @return bool 575 683 */ 576 public function Quit($close_on_error =true) {577 $this->error = null; //so there is no confusion684 function Quit($close_on_error=true) { 685 $this->error = null; # so there is no confusion 578 686 579 687 if(!$this->connected()) { … … 583 691 } 584 692 585 //send the quit command to the server693 # send the quit command to the server 586 694 fputs($this->smtp_conn,"quit" . $this->CRLF); 587 695 588 //get any good-bye messages696 # get any good-bye messages 589 697 $byemsg = $this->get_lines(); 590 698 591 699 if($this->do_debug >= 2) { 592 echo "SMTP -> FROM SERVER:" . $ byemsg . $this->CRLF . '<br />';700 echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg; 593 701 } 594 702 … … 598 706 $code = substr($byemsg,0,3); 599 707 if($code != 221) { 600 //use e as a tmp var cause Close will overwrite $this->error708 # use e as a tmp var cause Close will overwrite $this->error 601 709 $e = array("error" => "SMTP server rejected quit command", 602 710 "smtp_code" => $code, … … 604 712 $rval = false; 605 713 if($this->do_debug >= 1) { 606 echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'; 714 echo "SMTP -> ERROR: " . $e["error"] . ": " . 715 $byemsg . $this->CRLF; 607 716 } 608 717 } … … 627 736 * @return bool 628 737 */ 629 publicfunction Recipient($to) {630 $this->error = null; //so no confusion is caused738 function Recipient($to) { 739 $this->error = null; # so no confusion is caused 631 740 632 741 if(!$this->connected()) { … … 642 751 643 752 if($this->do_debug >= 2) { 644 echo "SMTP -> FROM SERVER:" . $ rply . $this->CRLF . '<br />';753 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 645 754 } 646 755 … … 651 760 "smtp_msg" => substr($rply,4)); 652 761 if($this->do_debug >= 1) { 653 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 762 echo "SMTP -> ERROR: " . $this->error["error"] . 763 ": " . $rply . $this->CRLF; 654 764 } 655 765 return false; … … 670 780 * @return bool 671 781 */ 672 publicfunction Reset() {673 $this->error = null; //so no confusion is caused782 function Reset() { 783 $this->error = null; # so no confusion is caused 674 784 675 785 if(!$this->connected()) { … … 685 795 686 796 if($this->do_debug >= 2) { 687 echo "SMTP -> FROM SERVER:" . $ rply . $this->CRLF . '<br />';797 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 688 798 } 689 799 … … 694 804 "smtp_msg" => substr($rply,4)); 695 805 if($this->do_debug >= 1) { 696 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 697 } 698 return false; 699 } 700 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 } 701 860 return true; 702 861 } … … 718 877 * @return bool 719 878 */ 720 publicfunction SendAndMail($from) {721 $this->error = null; //so no confusion is caused879 function SendAndMail($from) { 880 $this->error = null; # so no confusion is caused 722 881 723 882 if(!$this->connected()) { … … 733 892 734 893 if($this->do_debug >= 2) { 735 echo "SMTP -> FROM SERVER:" . $ rply . $this->CRLF . '<br />';894 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; 736 895 } 737 896 … … 742 901 "smtp_msg" => substr($rply,4)); 743 902 if($this->do_debug >= 1) { 744 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 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; 745 953 } 746 954 return false; … … 762 970 * @return bool 763 971 */ 764 publicfunction Turn() {972 function Turn() { 765 973 $this->error = array("error" => "This method, TURN, of the SMTP ". 766 974 "is not implemented"); 767 975 if($this->do_debug >= 1) { 768 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';976 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF; 769 977 } 770 978 return false; … … 772 980 773 981 /** 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 ///////////////////////////////////////////////// 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 ******************************************************************/ 785 1029 786 1030 /** … … 793 1037 * @return string 794 1038 */ 795 privatefunction get_lines() {1039 function get_lines() { 796 1040 $data = ""; 797 1041 while($str = @fgets($this->smtp_conn,515)) { 798 1042 if($this->do_debug >= 4) { 799 echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'; 800 echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'; 1043 echo "SMTP -> get_lines(): \$data was \"$data\"" . 1044 $this->CRLF; 1045 echo "SMTP -> get_lines(): \$str is \"$str\"" . 1046 $this->CRLF; 801 1047 } 802 1048 $data .= $str; 803 1049 if($this->do_debug >= 4) { 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 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 807 1054 if(substr($str,3,1) == " ") { break; } 808 1055 } … … 812 1059 } 813 1060 814 ?> 1061 1062 ?>
Note: See TracChangeset
for help on using the changeset viewer.