-
+ 5EAB6FD66B7DA79B8F58D432AD77E93FF43C04D06AD37B52D76179B2351A57C581F5592693B1A9B7D9D9A14C2A1C567871A9C9F4E9E1368A8EBE15DB3E03B866mp-wp/wp-includes/class-smtp.php(0 . 0)(1 . 1062)
79212 <?php
79213 /*~ class.smtp.php
79214 .---------------------------------------------------------------------------.
79215 | Software: PHPMailer - PHP email class |
79216 | Version: 2.0.2 |
79217 | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
79218 | Info: http://phpmailer.sourceforge.net |
79219 | Support: http://sourceforge.net/projects/phpmailer/ |
79220 | ------------------------------------------------------------------------- |
79221 | Author: Andy Prevost (project admininistrator) |
79222 | Author: Brent R. Matzelle (original founder) |
79223 | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
79224 | Copyright (c) 2001-2003, Brent R. Matzelle |
79225 | ------------------------------------------------------------------------- |
79226 | License: Distributed under the Lesser General Public License (LGPL) |
79227 | http://www.gnu.org/copyleft/lesser.html |
79228 | This program is distributed in the hope that it will be useful - WITHOUT |
79229 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
79230 | FITNESS FOR A PARTICULAR PURPOSE. |
79231 | ------------------------------------------------------------------------- |
79232 | We offer a number of paid services (www.codeworxtech.com): |
79233 | - Web Hosting on highly optimized fast and secure servers |
79234 | - Technology Consulting |
79235 | - Oursourcing (highly qualified programmers and graphic designers) |
79236 '---------------------------------------------------------------------------'
79237 */
79238 /**
79239 * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
79240 * commands except TURN which will always return a not implemented
79241 * error. SMTP also provides some utility methods for sending mail
79242 * to an SMTP server.
79243 * @package PHPMailer
79244 * @author Chris Ryan
79245 */
79246
79247 class SMTP
79248 {
79249 /**
79250 * SMTP server port
79251 * @var int
79252 */
79253 var $SMTP_PORT = 25;
79254
79255 /**
79256 * SMTP reply line ending
79257 * @var string
79258 */
79259 var $CRLF = "\r\n";
79260
79261 /**
79262 * Sets whether debugging is turned on
79263 * @var bool
79264 */
79265 var $do_debug; # the level of debug to perform
79266
79267 /**
79268 * Sets VERP use on/off (default is off)
79269 * @var bool
79270 */
79271 var $do_verp = false;
79272
79273 /**#@+
79274 * @access private
79275 */
79276 var $smtp_conn; # the socket to the server
79277 var $error; # error if any on the last call
79278 var $helo_rply; # the reply the server sent to us for HELO
79279 /**#@-*/
79280
79281 /**
79282 * Initialize the class so that the data is in a known state.
79283 * @access public
79284 * @return void
79285 */
79286 function SMTP() {
79287 $this->smtp_conn = 0;
79288 $this->error = null;
79289 $this->helo_rply = null;
79290
79291 $this->do_debug = 0;
79292 }
79293
79294 /*************************************************************
79295 * CONNECTION FUNCTIONS *
79296 ***********************************************************/
79297
79298 /**
79299 * Connect to the server specified on the port specified.
79300 * If the port is not specified use the default SMTP_PORT.
79301 * If tval is specified then a connection will try and be
79302 * established with the server for that number of seconds.
79303 * If tval is not specified the default is 30 seconds to
79304 * try on the connection.
79305 *
79306 * SMTP CODE SUCCESS: 220
79307 * SMTP CODE FAILURE: 421
79308 * @access public
79309 * @return bool
79310 */
79311 function Connect($host,$port=0,$tval=30) {
79312 # set the error val to null so there is no confusion
79313 $this->error = null;
79314
79315 # make sure we are __not__ connected
79316 if($this->connected()) {
79317 # ok we are connected! what should we do?
79318 # for now we will just give an error saying we
79319 # are already connected
79320 $this->error = array("error" => "Already connected to a server");
79321 return false;
79322 }
79323
79324 if(empty($port)) {
79325 $port = $this->SMTP_PORT;
79326 }
79327
79328 #connect to the smtp server
79329 $this->smtp_conn = fsockopen($host, # the host of the server
79330 $port, # the port to use
79331 $errno, # error number if any
79332 $errstr, # error message if any
79333 $tval); # give up after ? secs
79334 # verify we connected properly
79335 if(empty($this->smtp_conn)) {
79336 $this->error = array("error" => "Failed to connect to server",
79337 "errno" => $errno,
79338 "errstr" => $errstr);
79339 if($this->do_debug >= 1) {
79340 echo "SMTP -> ERROR: " . $this->error["error"] .
79341 ": $errstr ($errno)" . $this->CRLF;
79342 }
79343 return false;
79344 }
79345
79346 # sometimes the SMTP server takes a little longer to respond
79347 # so we will give it a longer timeout for the first read
79348 // Windows still does not have support for this timeout function
79349 if(substr(PHP_OS, 0, 3) != "WIN")
79350 socket_set_timeout($this->smtp_conn, $tval, 0);
79351
79352 # get any announcement stuff
79353 $announce = $this->get_lines();
79354
79355 # set the timeout of any socket functions at 1/10 of a second
79356 //if(function_exists("socket_set_timeout"))
79357 // socket_set_timeout($this->smtp_conn, 0, 100000);
79358
79359 if($this->do_debug >= 2) {
79360 echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
79361 }
79362
79363 return true;
79364 }
79365
79366 /**
79367 * Performs SMTP authentication. Must be run after running the
79368 * Hello() method. Returns true if successfully authenticated.
79369 * @access public
79370 * @return bool
79371 */
79372 function Authenticate($username, $password) {
79373 // Start authentication
79374 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
79375
79376 $rply = $this->get_lines();
79377 $code = substr($rply,0,3);
79378
79379 if($code != 334) {
79380 $this->error =
79381 array("error" => "AUTH not accepted from server",
79382 "smtp_code" => $code,
79383 "smtp_msg" => substr($rply,4));
79384 if($this->do_debug >= 1) {
79385 echo "SMTP -> ERROR: " . $this->error["error"] .
79386 ": " . $rply . $this->CRLF;
79387 }
79388 return false;
79389 }
79390
79391 // Send encoded username
79392 fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
79393
79394 $rply = $this->get_lines();
79395 $code = substr($rply,0,3);
79396
79397 if($code != 334) {
79398 $this->error =
79399 array("error" => "Username not accepted from server",
79400 "smtp_code" => $code,
79401 "smtp_msg" => substr($rply,4));
79402 if($this->do_debug >= 1) {
79403 echo "SMTP -> ERROR: " . $this->error["error"] .
79404 ": " . $rply . $this->CRLF;
79405 }
79406 return false;
79407 }
79408
79409 // Send encoded password
79410 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
79411
79412 $rply = $this->get_lines();
79413 $code = substr($rply,0,3);
79414
79415 if($code != 235) {
79416 $this->error =
79417 array("error" => "Password not accepted from server",
79418 "smtp_code" => $code,
79419 "smtp_msg" => substr($rply,4));
79420 if($this->do_debug >= 1) {
79421 echo "SMTP -> ERROR: " . $this->error["error"] .
79422 ": " . $rply . $this->CRLF;
79423 }
79424 return false;
79425 }
79426
79427 return true;
79428 }
79429
79430 /**
79431 * Returns true if connected to a server otherwise false
79432 * @access private
79433 * @return bool
79434 */
79435 function Connected() {
79436 if(!empty($this->smtp_conn)) {
79437 $sock_status = socket_get_status($this->smtp_conn);
79438 if($sock_status["eof"]) {
79439 # hmm this is an odd situation... the socket is
79440 # valid but we are not connected anymore
79441 if($this->do_debug >= 1) {
79442 echo "SMTP -> NOTICE:" . $this->CRLF .
79443 "EOF caught while checking if connected";
79444 }
79445 $this->Close();
79446 return false;
79447 }
79448 return true; # everything looks good
79449 }
79450 return false;
79451 }
79452
79453 /**
79454 * Closes the socket and cleans up the state of the class.
79455 * It is not considered good to use this function without
79456 * first trying to use QUIT.
79457 * @access public
79458 * @return void
79459 */
79460 function Close() {
79461 $this->error = null; # so there is no confusion
79462 $this->helo_rply = null;
79463 if(!empty($this->smtp_conn)) {
79464 # close the connection and cleanup
79465 fclose($this->smtp_conn);
79466 $this->smtp_conn = 0;
79467 }
79468 }
79469
79470 /***************************************************************
79471 * SMTP COMMANDS *
79472 *************************************************************/
79473
79474 /**
79475 * Issues a data command and sends the msg_data to the server
79476 * finializing the mail transaction. $msg_data is the message
79477 * that is to be send with the headers. Each header needs to be
79478 * on a single line followed by a <CRLF> with the message headers
79479 * and the message body being seperated by and additional <CRLF>.
79480 *
79481 * Implements rfc 821: DATA <CRLF>
79482 *
79483 * SMTP CODE INTERMEDIATE: 354
79484 * [data]
79485 * <CRLF>.<CRLF>
79486 * SMTP CODE SUCCESS: 250
79487 * SMTP CODE FAILURE: 552,554,451,452
79488 * SMTP CODE FAILURE: 451,554
79489 * SMTP CODE ERROR : 500,501,503,421
79490 * @access public
79491 * @return bool
79492 */
79493 function Data($msg_data) {
79494 $this->error = null; # so no confusion is caused
79495
79496 if(!$this->connected()) {
79497 $this->error = array(
79498 "error" => "Called Data() without being connected");
79499 return false;
79500 }
79501
79502 fputs($this->smtp_conn,"DATA" . $this->CRLF);
79503
79504 $rply = $this->get_lines();
79505 $code = substr($rply,0,3);
79506
79507 if($this->do_debug >= 2) {
79508 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
79509 }
79510
79511 if($code != 354) {
79512 $this->error =
79513 array("error" => "DATA command not accepted from server",
79514 "smtp_code" => $code,
79515 "smtp_msg" => substr($rply,4));
79516 if($this->do_debug >= 1) {
79517 echo "SMTP -> ERROR: " . $this->error["error"] .
79518 ": " . $rply . $this->CRLF;
79519 }
79520 return false;
79521 }
79522
79523 # the server is ready to accept data!
79524 # according to rfc 821 we should not send more than 1000
79525 # including the CRLF
79526 # characters on a single line so we will break the data up
79527 # into lines by \r and/or \n then if needed we will break
79528 # each of those into smaller lines to fit within the limit.
79529 # in addition we will be looking for lines that start with
79530 # a period '.' and append and additional period '.' to that
79531 # line. NOTE: this does not count towards are limit.
79532
79533 # normalize the line breaks so we know the explode works
79534 $msg_data = str_replace("\r\n","\n",$msg_data);
79535 $msg_data = str_replace("\r","\n",$msg_data);
79536 $lines = explode("\n",$msg_data);
79537
79538 # we need to find a good way to determine is headers are
79539 # in the msg_data or if it is a straight msg body
79540 # currently I am assuming rfc 822 definitions of msg headers
79541 # and if the first field of the first line (':' sperated)
79542 # does not contain a space then it _should_ be a header
79543 # and we can process all lines before a blank "" line as
79544 # headers.
79545 $field = substr($lines[0],0,strpos($lines[0],":"));
79546 $in_headers = false;
79547 if(!empty($field) && !strstr($field," ")) {
79548 $in_headers = true;
79549 }
79550
79551 $max_line_length = 998; # used below; set here for ease in change
79552
79553 while(list(,$line) = @each($lines)) {
79554 $lines_out = null;
79555 if($line == "" && $in_headers) {
79556 $in_headers = false;
79557 }
79558 # ok we need to break this line up into several
79559 # smaller lines
79560 while(strlen($line) > $max_line_length) {
79561 $pos = strrpos(substr($line,0,$max_line_length)," ");
79562
79563 # Patch to fix DOS attack
79564 if(!$pos) {
79565 $pos = $max_line_length - 1;
79566 }
79567
79568 $lines_out[] = substr($line,0,$pos);
79569 $line = substr($line,$pos + 1);
79570 # if we are processing headers we need to
79571 # add a LWSP-char to the front of the new line
79572 # rfc 822 on long msg headers
79573 if($in_headers) {
79574 $line = "\t" . $line;
79575 }
79576 }
79577 $lines_out[] = $line;
79578
79579 # now send the lines to the server
79580 while(list(,$line_out) = @each($lines_out)) {
79581 if(strlen($line_out) > 0)
79582 {
79583 if(substr($line_out, 0, 1) == ".") {
79584 $line_out = "." . $line_out;
79585 }
79586 }
79587 fputs($this->smtp_conn,$line_out . $this->CRLF);
79588 }
79589 }
79590
79591 # ok all the message data has been sent so lets get this
79592 # over with aleady
79593 fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
79594
79595 $rply = $this->get_lines();
79596 $code = substr($rply,0,3);
79597
79598 if($this->do_debug >= 2) {
79599 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
79600 }
79601
79602 if($code != 250) {
79603 $this->error =
79604 array("error" => "DATA not accepted from server",
79605 "smtp_code" => $code,
79606 "smtp_msg" => substr($rply,4));
79607 if($this->do_debug >= 1) {
79608 echo "SMTP -> ERROR: " . $this->error["error"] .
79609 ": " . $rply . $this->CRLF;
79610 }
79611 return false;
79612 }
79613 return true;
79614 }
79615
79616 /**
79617 * Expand takes the name and asks the server to list all the
79618 * people who are members of the _list_. Expand will return
79619 * back and array of the result or false if an error occurs.
79620 * Each value in the array returned has the format of:
79621 * [ <full-name> <sp> ] <path>
79622 * The definition of <path> is defined in rfc 821
79623 *
79624 * Implements rfc 821: EXPN <SP> <string> <CRLF>
79625 *
79626 * SMTP CODE SUCCESS: 250
79627 * SMTP CODE FAILURE: 550
79628 * SMTP CODE ERROR : 500,501,502,504,421
79629 * @access public
79630 * @return string array
79631 */
79632 function Expand($name) {
79633 $this->error = null; # so no confusion is caused
79634
79635 if(!$this->connected()) {
79636 $this->error = array(
79637 "error" => "Called Expand() without being connected");
79638 return false;
79639 }
79640
79641 fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
79642
79643 $rply = $this->get_lines();
79644 $code = substr($rply,0,3);
79645
79646 if($this->do_debug >= 2) {
79647 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
79648 }
79649
79650 if($code != 250) {
79651 $this->error =
79652 array("error" => "EXPN not accepted from server",
79653 "smtp_code" => $code,
79654 "smtp_msg" => substr($rply,4));
79655 if($this->do_debug >= 1) {
79656 echo "SMTP -> ERROR: " . $this->error["error"] .
79657 ": " . $rply . $this->CRLF;
79658 }
79659 return false;
79660 }
79661
79662 # parse the reply and place in our array to return to user
79663 $entries = explode($this->CRLF,$rply);
79664 while(list(,$l) = @each($entries)) {
79665 $list[] = substr($l,4);
79666 }
79667
79668 return $list;
79669 }
79670
79671 /**
79672 * Sends the HELO command to the smtp server.
79673 * This makes sure that we and the server are in
79674 * the same known state.
79675 *
79676 * Implements from rfc 821: HELO <SP> <domain> <CRLF>
79677 *
79678 * SMTP CODE SUCCESS: 250
79679 * SMTP CODE ERROR : 500, 501, 504, 421
79680 * @access public
79681 * @return bool
79682 */
79683 function Hello($host="") {
79684 $this->error = null; # so no confusion is caused
79685
79686 if(!$this->connected()) {
79687 $this->error = array(
79688 "error" => "Called Hello() without being connected");
79689 return false;
79690 }
79691
79692 # if a hostname for the HELO was not specified determine
79693 # a suitable one to send
79694 if(empty($host)) {
79695 # we need to determine some sort of appopiate default
79696 # to send to the server
79697 $host = "localhost";
79698 }
79699
79700 // Send extended hello first (RFC 2821)
79701 if(!$this->SendHello("EHLO", $host))
79702 {
79703 if(!$this->SendHello("HELO", $host))
79704 return false;
79705 }
79706
79707 return true;
79708 }
79709
79710 /**
79711 * Sends a HELO/EHLO command.
79712 * @access private
79713 * @return bool
79714 */
79715 function SendHello($hello, $host) {
79716 fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
79717
79718 $rply = $this->get_lines();
79719 $code = substr($rply,0,3);
79720
79721 if($this->do_debug >= 2) {
79722 echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
79723 }
79724
79725 if($code != 250) {
79726 $this->error =
79727 array("error" => $hello . " not accepted from server",
79728 "smtp_code" => $code,
79729 "smtp_msg" => substr($rply,4));
79730 if($this->do_debug >= 1) {
79731 echo "SMTP -> ERROR: " . $this->error["error"] .
79732 ": " . $rply . $this->CRLF;
79733 }
79734 return false;
79735 }
79736
79737 $this->helo_rply = $rply;
79738
79739 return true;
79740 }
79741
79742 /**
79743 * Gets help information on the keyword specified. If the keyword
79744 * is not specified then returns generic help, ussually contianing
79745 * A list of keywords that help is available on. This function
79746 * returns the results back to the user. It is up to the user to
79747 * handle the returned data. If an error occurs then false is
79748 * returned with $this->error set appropiately.
79749 *
79750 * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
79751 *
79752 * SMTP CODE SUCCESS: 211,214
79753 * SMTP CODE ERROR : 500,501,502,504,421
79754 * @access public
79755 * @return string
79756 */
79757 function Help($keyword="") {
79758 $this->error = null; # to avoid confusion
79759
79760 if(!$this->connected()) {
79761 $this->error = array(
79762 "error" => "Called Help() without being connected");
79763 return false;
79764 }
79765
79766 $extra = "";
79767 if(!empty($keyword)) {
79768 $extra = " " . $keyword;
79769 }
79770
79771 fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
79772
79773 $rply = $this->get_lines();
79774 $code = substr($rply,0,3);
79775
79776 if($this->do_debug >= 2) {
79777 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
79778 }
79779
79780 if($code != 211 && $code != 214) {
79781 $this->error =
79782 array("error" => "HELP not accepted from server",
79783 "smtp_code" => $code,
79784 "smtp_msg" => substr($rply,4));
79785 if($this->do_debug >= 1) {
79786 echo "SMTP -> ERROR: " . $this->error["error"] .
79787 ": " . $rply . $this->CRLF;
79788 }
79789 return false;
79790 }
79791
79792 return $rply;
79793 }
79794
79795 /**
79796 * Starts a mail transaction from the email address specified in
79797 * $from. Returns true if successful or false otherwise. If True
79798 * the mail transaction is started and then one or more Recipient
79799 * commands may be called followed by a Data command.
79800 *
79801 * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
79802 *
79803 * SMTP CODE SUCCESS: 250
79804 * SMTP CODE SUCCESS: 552,451,452
79805 * SMTP CODE SUCCESS: 500,501,421
79806 * @access public
79807 * @return bool
79808 */
79809 function Mail($from) {
79810 $this->error = null; # so no confusion is caused
79811
79812 if(!$this->connected()) {
79813 $this->error = array(
79814 "error" => "Called Mail() without being connected");
79815 return false;
79816 }
79817
79818 $useVerp = ($this->do_verp ? "XVERP" : "");
79819 fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
79820
79821 $rply = $this->get_lines();
79822 $code = substr($rply,0,3);
79823
79824 if($this->do_debug >= 2) {
79825 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
79826 }
79827
79828 if($code != 250) {
79829 $this->error =
79830 array("error" => "MAIL not accepted from server",
79831 "smtp_code" => $code,
79832 "smtp_msg" => substr($rply,4));
79833 if($this->do_debug >= 1) {
79834 echo "SMTP -> ERROR: " . $this->error["error"] .
79835 ": " . $rply . $this->CRLF;
79836 }
79837 return false;
79838 }
79839 return true;
79840 }
79841
79842 /**
79843 * Sends the command NOOP to the SMTP server.
79844 *
79845 * Implements from rfc 821: NOOP <CRLF>
79846 *
79847 * SMTP CODE SUCCESS: 250
79848 * SMTP CODE ERROR : 500, 421
79849 * @access public
79850 * @return bool
79851 */
79852 function Noop() {
79853 $this->error = null; # so no confusion is caused
79854
79855 if(!$this->connected()) {
79856 $this->error = array(
79857 "error" => "Called Noop() without being connected");
79858 return false;
79859 }
79860
79861 fputs($this->smtp_conn,"NOOP" . $this->CRLF);
79862
79863 $rply = $this->get_lines();
79864 $code = substr($rply,0,3);
79865
79866 if($this->do_debug >= 2) {
79867 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
79868 }
79869
79870 if($code != 250) {
79871 $this->error =
79872 array("error" => "NOOP not accepted from server",
79873 "smtp_code" => $code,
79874 "smtp_msg" => substr($rply,4));
79875 if($this->do_debug >= 1) {
79876 echo "SMTP -> ERROR: " . $this->error["error"] .
79877 ": " . $rply . $this->CRLF;
79878 }
79879 return false;
79880 }
79881 return true;
79882 }
79883
79884 /**
79885 * Sends the quit command to the server and then closes the socket
79886 * if there is no error or the $close_on_error argument is true.
79887 *
79888 * Implements from rfc 821: QUIT <CRLF>
79889 *
79890 * SMTP CODE SUCCESS: 221
79891 * SMTP CODE ERROR : 500
79892 * @access public
79893 * @return bool
79894 */
79895 function Quit($close_on_error=true) {
79896 $this->error = null; # so there is no confusion
79897
79898 if(!$this->connected()) {
79899 $this->error = array(
79900 "error" => "Called Quit() without being connected");
79901 return false;
79902 }
79903
79904 # send the quit command to the server
79905 fputs($this->smtp_conn,"quit" . $this->CRLF);
79906
79907 # get any good-bye messages
79908 $byemsg = $this->get_lines();
79909
79910 if($this->do_debug >= 2) {
79911 echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
79912 }
79913
79914 $rval = true;
79915 $e = null;
79916
79917 $code = substr($byemsg,0,3);
79918 if($code != 221) {
79919 # use e as a tmp var cause Close will overwrite $this->error
79920 $e = array("error" => "SMTP server rejected quit command",
79921 "smtp_code" => $code,
79922 "smtp_rply" => substr($byemsg,4));
79923 $rval = false;
79924 if($this->do_debug >= 1) {
79925 echo "SMTP -> ERROR: " . $e["error"] . ": " .
79926 $byemsg . $this->CRLF;
79927 }
79928 }
79929
79930 if(empty($e) || $close_on_error) {
79931 $this->Close();
79932 }
79933
79934 return $rval;
79935 }
79936
79937 /**
79938 * Sends the command RCPT to the SMTP server with the TO: argument of $to.
79939 * Returns true if the recipient was accepted false if it was rejected.
79940 *
79941 * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
79942 *
79943 * SMTP CODE SUCCESS: 250,251
79944 * SMTP CODE FAILURE: 550,551,552,553,450,451,452
79945 * SMTP CODE ERROR : 500,501,503,421
79946 * @access public
79947 * @return bool
79948 */
79949 function Recipient($to) {
79950 $this->error = null; # so no confusion is caused
79951
79952 if(!$this->connected()) {
79953 $this->error = array(
79954 "error" => "Called Recipient() without being connected");
79955 return false;
79956 }
79957
79958 fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
79959
79960 $rply = $this->get_lines();
79961 $code = substr($rply,0,3);
79962
79963 if($this->do_debug >= 2) {
79964 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
79965 }
79966
79967 if($code != 250 && $code != 251) {
79968 $this->error =
79969 array("error" => "RCPT not accepted from server",
79970 "smtp_code" => $code,
79971 "smtp_msg" => substr($rply,4));
79972 if($this->do_debug >= 1) {
79973 echo "SMTP -> ERROR: " . $this->error["error"] .
79974 ": " . $rply . $this->CRLF;
79975 }
79976 return false;
79977 }
79978 return true;
79979 }
79980
79981 /**
79982 * Sends the RSET command to abort and transaction that is
79983 * currently in progress. Returns true if successful false
79984 * otherwise.
79985 *
79986 * Implements rfc 821: RSET <CRLF>
79987 *
79988 * SMTP CODE SUCCESS: 250
79989 * SMTP CODE ERROR : 500,501,504,421
79990 * @access public
79991 * @return bool
79992 */
79993 function Reset() {
79994 $this->error = null; # so no confusion is caused
79995
79996 if(!$this->connected()) {
79997 $this->error = array(
79998 "error" => "Called Reset() without being connected");
79999 return false;
80000 }
80001
80002 fputs($this->smtp_conn,"RSET" . $this->CRLF);
80003
80004 $rply = $this->get_lines();
80005 $code = substr($rply,0,3);
80006
80007 if($this->do_debug >= 2) {
80008 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
80009 }
80010
80011 if($code != 250) {
80012 $this->error =
80013 array("error" => "RSET failed",
80014 "smtp_code" => $code,
80015 "smtp_msg" => substr($rply,4));
80016 if($this->do_debug >= 1) {
80017 echo "SMTP -> ERROR: " . $this->error["error"] .
80018 ": " . $rply . $this->CRLF;
80019 }
80020 return false;
80021 }
80022
80023 return true;
80024 }
80025
80026 /**
80027 * Starts a mail transaction from the email address specified in
80028 * $from. Returns true if successful or false otherwise. If True
80029 * the mail transaction is started and then one or more Recipient
80030 * commands may be called followed by a Data command. This command
80031 * will send the message to the users terminal if they are logged
80032 * in.
80033 *
80034 * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
80035 *
80036 * SMTP CODE SUCCESS: 250
80037 * SMTP CODE SUCCESS: 552,451,452
80038 * SMTP CODE SUCCESS: 500,501,502,421
80039 * @access public
80040 * @return bool
80041 */
80042 function Send($from) {
80043 $this->error = null; # so no confusion is caused
80044
80045 if(!$this->connected()) {
80046 $this->error = array(
80047 "error" => "Called Send() without being connected");
80048 return false;
80049 }
80050
80051 fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
80052
80053 $rply = $this->get_lines();
80054 $code = substr($rply,0,3);
80055
80056 if($this->do_debug >= 2) {
80057 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
80058 }
80059
80060 if($code != 250) {
80061 $this->error =
80062 array("error" => "SEND not accepted from server",
80063 "smtp_code" => $code,
80064 "smtp_msg" => substr($rply,4));
80065 if($this->do_debug >= 1) {
80066 echo "SMTP -> ERROR: " . $this->error["error"] .
80067 ": " . $rply . $this->CRLF;
80068 }
80069 return false;
80070 }
80071 return true;
80072 }
80073
80074 /**
80075 * Starts a mail transaction from the email address specified in
80076 * $from. Returns true if successful or false otherwise. If True
80077 * the mail transaction is started and then one or more Recipient
80078 * commands may be called followed by a Data command. This command
80079 * will send the message to the users terminal if they are logged
80080 * in and send them an email.
80081 *
80082 * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
80083 *
80084 * SMTP CODE SUCCESS: 250
80085 * SMTP CODE SUCCESS: 552,451,452
80086 * SMTP CODE SUCCESS: 500,501,502,421
80087 * @access public
80088 * @return bool
80089 */
80090 function SendAndMail($from) {
80091 $this->error = null; # so no confusion is caused
80092
80093 if(!$this->connected()) {
80094 $this->error = array(
80095 "error" => "Called SendAndMail() without being connected");
80096 return false;
80097 }
80098
80099 fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
80100
80101 $rply = $this->get_lines();
80102 $code = substr($rply,0,3);
80103
80104 if($this->do_debug >= 2) {
80105 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
80106 }
80107
80108 if($code != 250) {
80109 $this->error =
80110 array("error" => "SAML not accepted from server",
80111 "smtp_code" => $code,
80112 "smtp_msg" => substr($rply,4));
80113 if($this->do_debug >= 1) {
80114 echo "SMTP -> ERROR: " . $this->error["error"] .
80115 ": " . $rply . $this->CRLF;
80116 }
80117 return false;
80118 }
80119 return true;
80120 }
80121
80122 /**
80123 * Starts a mail transaction from the email address specified in
80124 * $from. Returns true if successful or false otherwise. If True
80125 * the mail transaction is started and then one or more Recipient
80126 * commands may be called followed by a Data command. This command
80127 * will send the message to the users terminal if they are logged
80128 * in or mail it to them if they are not.
80129 *
80130 * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
80131 *
80132 * SMTP CODE SUCCESS: 250
80133 * SMTP CODE SUCCESS: 552,451,452
80134 * SMTP CODE SUCCESS: 500,501,502,421
80135 * @access public
80136 * @return bool
80137 */
80138 function SendOrMail($from) {
80139 $this->error = null; # so no confusion is caused
80140
80141 if(!$this->connected()) {
80142 $this->error = array(
80143 "error" => "Called SendOrMail() without being connected");
80144 return false;
80145 }
80146
80147 fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
80148
80149 $rply = $this->get_lines();
80150 $code = substr($rply,0,3);
80151
80152 if($this->do_debug >= 2) {
80153 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
80154 }
80155
80156 if($code != 250) {
80157 $this->error =
80158 array("error" => "SOML not accepted from server",
80159 "smtp_code" => $code,
80160 "smtp_msg" => substr($rply,4));
80161 if($this->do_debug >= 1) {
80162 echo "SMTP -> ERROR: " . $this->error["error"] .
80163 ": " . $rply . $this->CRLF;
80164 }
80165 return false;
80166 }
80167 return true;
80168 }
80169
80170 /**
80171 * This is an optional command for SMTP that this class does not
80172 * support. This method is here to make the RFC821 Definition
80173 * complete for this class and __may__ be implimented in the future
80174 *
80175 * Implements from rfc 821: TURN <CRLF>
80176 *
80177 * SMTP CODE SUCCESS: 250
80178 * SMTP CODE FAILURE: 502
80179 * SMTP CODE ERROR : 500, 503
80180 * @access public
80181 * @return bool
80182 */
80183 function Turn() {
80184 $this->error = array("error" => "This method, TURN, of the SMTP ".
80185 "is not implemented");
80186 if($this->do_debug >= 1) {
80187 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
80188 }
80189 return false;
80190 }
80191
80192 /**
80193 * Verifies that the name is recognized by the server.
80194 * Returns false if the name could not be verified otherwise
80195 * the response from the server is returned.
80196 *
80197 * Implements rfc 821: VRFY <SP> <string> <CRLF>
80198 *
80199 * SMTP CODE SUCCESS: 250,251
80200 * SMTP CODE FAILURE: 550,551,553
80201 * SMTP CODE ERROR : 500,501,502,421
80202 * @access public
80203 * @return int
80204 */
80205 function Verify($name) {
80206 $this->error = null; # so no confusion is caused
80207
80208 if(!$this->connected()) {
80209 $this->error = array(
80210 "error" => "Called Verify() without being connected");
80211 return false;
80212 }
80213
80214 fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
80215
80216 $rply = $this->get_lines();
80217 $code = substr($rply,0,3);
80218
80219 if($this->do_debug >= 2) {
80220 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
80221 }
80222
80223 if($code != 250 && $code != 251) {
80224 $this->error =
80225 array("error" => "VRFY failed on name '$name'",
80226 "smtp_code" => $code,
80227 "smtp_msg" => substr($rply,4));
80228 if($this->do_debug >= 1) {
80229 echo "SMTP -> ERROR: " . $this->error["error"] .
80230 ": " . $rply . $this->CRLF;
80231 }
80232 return false;
80233 }
80234 return $rply;
80235 }
80236
80237 /*******************************************************************
80238 * INTERNAL FUNCTIONS *
80239 ******************************************************************/
80240
80241 /**
80242 * Read in as many lines as possible
80243 * either before eof or socket timeout occurs on the operation.
80244 * With SMTP we can tell if we have more lines to read if the
80245 * 4th character is '-' symbol. If it is a space then we don't
80246 * need to read anything else.
80247 * @access private
80248 * @return string
80249 */
80250 function get_lines() {
80251 $data = "";
80252 while($str = @fgets($this->smtp_conn,515)) {
80253 if($this->do_debug >= 4) {
80254 echo "SMTP -> get_lines(): \$data was \"$data\"" .
80255 $this->CRLF;
80256 echo "SMTP -> get_lines(): \$str is \"$str\"" .
80257 $this->CRLF;
80258 }
80259 $data .= $str;
80260 if($this->do_debug >= 4) {
80261 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
80262 }
80263 # if the 4th character is a space then we are done reading
80264 # so just break the loop
80265 if(substr($str,3,1) == " ") { break; }
80266 }
80267 return $data;
80268 }
80269
80270 }
80271
80272
80273 ?>