raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /*~ class.smtp.php
mp-wp_genesis 3 .---------------------------------------------------------------------------.
mp-wp_genesis 4 | Software: PHPMailer - PHP email class |
mp-wp_genesis 5 | Version: 2.0.2 |
mp-wp_genesis 6 | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
mp-wp_genesis 7 | Info: http://phpmailer.sourceforge.net |
mp-wp_genesis 8 | Support: http://sourceforge.net/projects/phpmailer/ |
mp-wp_genesis 9 | ------------------------------------------------------------------------- |
mp-wp_genesis 10 | Author: Andy Prevost (project admininistrator) |
mp-wp_genesis 11 | Author: Brent R. Matzelle (original founder) |
mp-wp_genesis 12 | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
mp-wp_genesis 13 | Copyright (c) 2001-2003, Brent R. Matzelle |
mp-wp_genesis 14 | ------------------------------------------------------------------------- |
mp-wp_genesis 15 | License: Distributed under the Lesser General Public License (LGPL) |
mp-wp_genesis 16 | http://www.gnu.org/copyleft/lesser.html |
mp-wp_genesis 17 | This program is distributed in the hope that it will be useful - WITHOUT |
mp-wp_genesis 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mp-wp_genesis 19 | FITNESS FOR A PARTICULAR PURPOSE. |
mp-wp_genesis 20 | ------------------------------------------------------------------------- |
mp-wp_genesis 21 | We offer a number of paid services (www.codeworxtech.com): |
mp-wp_genesis 22 | - Web Hosting on highly optimized fast and secure servers |
mp-wp_genesis 23 | - Technology Consulting |
mp-wp_genesis 24 | - Oursourcing (highly qualified programmers and graphic designers) |
mp-wp_genesis 25 '---------------------------------------------------------------------------'
mp-wp_genesis 26 */
mp-wp_genesis 27 /**
mp-wp_genesis 28 * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
mp-wp_genesis 29 * commands except TURN which will always return a not implemented
mp-wp_genesis 30 * error. SMTP also provides some utility methods for sending mail
mp-wp_genesis 31 * to an SMTP server.
mp-wp_genesis 32 * @package PHPMailer
mp-wp_genesis 33 * @author Chris Ryan
mp-wp_genesis 34 */
mp-wp_genesis 35
mp-wp_genesis 36 class SMTP
mp-wp_genesis 37 {
mp-wp_genesis 38 /**
mp-wp_genesis 39 * SMTP server port
mp-wp_genesis 40 * @var int
mp-wp_genesis 41 */
mp-wp_genesis 42 var $SMTP_PORT = 25;
mp-wp_genesis 43
mp-wp_genesis 44 /**
mp-wp_genesis 45 * SMTP reply line ending
mp-wp_genesis 46 * @var string
mp-wp_genesis 47 */
mp-wp_genesis 48 var $CRLF = "\r\n";
mp-wp_genesis 49
mp-wp_genesis 50 /**
mp-wp_genesis 51 * Sets whether debugging is turned on
mp-wp_genesis 52 * @var bool
mp-wp_genesis 53 */
mp-wp_genesis 54 var $do_debug; # the level of debug to perform
mp-wp_genesis 55
mp-wp_genesis 56 /**
mp-wp_genesis 57 * Sets VERP use on/off (default is off)
mp-wp_genesis 58 * @var bool
mp-wp_genesis 59 */
mp-wp_genesis 60 var $do_verp = false;
mp-wp_genesis 61
mp-wp_genesis 62 /**#@+
mp-wp_genesis 63 * @access private
mp-wp_genesis 64 */
mp-wp_genesis 65 var $smtp_conn; # the socket to the server
mp-wp_genesis 66 var $error; # error if any on the last call
mp-wp_genesis 67 var $helo_rply; # the reply the server sent to us for HELO
mp-wp_genesis 68 /**#@-*/
mp-wp_genesis 69
mp-wp_genesis 70 /**
mp-wp_genesis 71 * Initialize the class so that the data is in a known state.
mp-wp_genesis 72 * @access public
mp-wp_genesis 73 * @return void
mp-wp_genesis 74 */
mp-wp_genesis 75 function SMTP() {
mp-wp_genesis 76 $this->smtp_conn = 0;
mp-wp_genesis 77 $this->error = null;
mp-wp_genesis 78 $this->helo_rply = null;
mp-wp_genesis 79
mp-wp_genesis 80 $this->do_debug = 0;
mp-wp_genesis 81 }
mp-wp_genesis 82
mp-wp_genesis 83 /*************************************************************
mp-wp_genesis 84 * CONNECTION FUNCTIONS *
mp-wp_genesis 85 ***********************************************************/
mp-wp_genesis 86
mp-wp_genesis 87 /**
mp-wp_genesis 88 * Connect to the server specified on the port specified.
mp-wp_genesis 89 * If the port is not specified use the default SMTP_PORT.
mp-wp_genesis 90 * If tval is specified then a connection will try and be
mp-wp_genesis 91 * established with the server for that number of seconds.
mp-wp_genesis 92 * If tval is not specified the default is 30 seconds to
mp-wp_genesis 93 * try on the connection.
mp-wp_genesis 94 *
mp-wp_genesis 95 * SMTP CODE SUCCESS: 220
mp-wp_genesis 96 * SMTP CODE FAILURE: 421
mp-wp_genesis 97 * @access public
mp-wp_genesis 98 * @return bool
mp-wp_genesis 99 */
mp-wp_genesis 100 function Connect($host,$port=0,$tval=30) {
mp-wp_genesis 101 # set the error val to null so there is no confusion
mp-wp_genesis 102 $this->error = null;
mp-wp_genesis 103
mp-wp_genesis 104 # make sure we are __not__ connected
mp-wp_genesis 105 if($this->connected()) {
mp-wp_genesis 106 # ok we are connected! what should we do?
mp-wp_genesis 107 # for now we will just give an error saying we
mp-wp_genesis 108 # are already connected
mp-wp_genesis 109 $this->error = array("error" => "Already connected to a server");
mp-wp_genesis 110 return false;
mp-wp_genesis 111 }
mp-wp_genesis 112
mp-wp_genesis 113 if(empty($port)) {
mp-wp_genesis 114 $port = $this->SMTP_PORT;
mp-wp_genesis 115 }
mp-wp_genesis 116
mp-wp_genesis 117 #connect to the smtp server
mp-wp_genesis 118 $this->smtp_conn = fsockopen($host, # the host of the server
mp-wp_genesis 119 $port, # the port to use
mp-wp_genesis 120 $errno, # error number if any
mp-wp_genesis 121 $errstr, # error message if any
mp-wp_genesis 122 $tval); # give up after ? secs
mp-wp_genesis 123 # verify we connected properly
mp-wp_genesis 124 if(empty($this->smtp_conn)) {
mp-wp_genesis 125 $this->error = array("error" => "Failed to connect to server",
mp-wp_genesis 126 "errno" => $errno,
mp-wp_genesis 127 "errstr" => $errstr);
mp-wp_genesis 128 if($this->do_debug >= 1) {
mp-wp_genesis 129 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 130 ": $errstr ($errno)" . $this->CRLF;
mp-wp_genesis 131 }
mp-wp_genesis 132 return false;
mp-wp_genesis 133 }
mp-wp_genesis 134
mp-wp_genesis 135 # sometimes the SMTP server takes a little longer to respond
mp-wp_genesis 136 # so we will give it a longer timeout for the first read
mp-wp_genesis 137 // Windows still does not have support for this timeout function
mp-wp_genesis 138 if(substr(PHP_OS, 0, 3) != "WIN")
mp-wp_genesis 139 socket_set_timeout($this->smtp_conn, $tval, 0);
mp-wp_genesis 140
mp-wp_genesis 141 # get any announcement stuff
mp-wp_genesis 142 $announce = $this->get_lines();
mp-wp_genesis 143
mp-wp_genesis 144 # set the timeout of any socket functions at 1/10 of a second
mp-wp_genesis 145 //if(function_exists("socket_set_timeout"))
mp-wp_genesis 146 // socket_set_timeout($this->smtp_conn, 0, 100000);
mp-wp_genesis 147
mp-wp_genesis 148 if($this->do_debug >= 2) {
mp-wp_genesis 149 echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
mp-wp_genesis 150 }
mp-wp_genesis 151
mp-wp_genesis 152 return true;
mp-wp_genesis 153 }
mp-wp_genesis 154
mp-wp_genesis 155 /**
mp-wp_genesis 156 * Performs SMTP authentication. Must be run after running the
mp-wp_genesis 157 * Hello() method. Returns true if successfully authenticated.
mp-wp_genesis 158 * @access public
mp-wp_genesis 159 * @return bool
mp-wp_genesis 160 */
mp-wp_genesis 161 function Authenticate($username, $password) {
mp-wp_genesis 162 // Start authentication
mp-wp_genesis 163 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
mp-wp_genesis 164
mp-wp_genesis 165 $rply = $this->get_lines();
mp-wp_genesis 166 $code = substr($rply,0,3);
mp-wp_genesis 167
mp-wp_genesis 168 if($code != 334) {
mp-wp_genesis 169 $this->error =
mp-wp_genesis 170 array("error" => "AUTH not accepted from server",
mp-wp_genesis 171 "smtp_code" => $code,
mp-wp_genesis 172 "smtp_msg" => substr($rply,4));
mp-wp_genesis 173 if($this->do_debug >= 1) {
mp-wp_genesis 174 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 175 ": " . $rply . $this->CRLF;
mp-wp_genesis 176 }
mp-wp_genesis 177 return false;
mp-wp_genesis 178 }
mp-wp_genesis 179
mp-wp_genesis 180 // Send encoded username
mp-wp_genesis 181 fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
mp-wp_genesis 182
mp-wp_genesis 183 $rply = $this->get_lines();
mp-wp_genesis 184 $code = substr($rply,0,3);
mp-wp_genesis 185
mp-wp_genesis 186 if($code != 334) {
mp-wp_genesis 187 $this->error =
mp-wp_genesis 188 array("error" => "Username not accepted from server",
mp-wp_genesis 189 "smtp_code" => $code,
mp-wp_genesis 190 "smtp_msg" => substr($rply,4));
mp-wp_genesis 191 if($this->do_debug >= 1) {
mp-wp_genesis 192 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 193 ": " . $rply . $this->CRLF;
mp-wp_genesis 194 }
mp-wp_genesis 195 return false;
mp-wp_genesis 196 }
mp-wp_genesis 197
mp-wp_genesis 198 // Send encoded password
mp-wp_genesis 199 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
mp-wp_genesis 200
mp-wp_genesis 201 $rply = $this->get_lines();
mp-wp_genesis 202 $code = substr($rply,0,3);
mp-wp_genesis 203
mp-wp_genesis 204 if($code != 235) {
mp-wp_genesis 205 $this->error =
mp-wp_genesis 206 array("error" => "Password not accepted from server",
mp-wp_genesis 207 "smtp_code" => $code,
mp-wp_genesis 208 "smtp_msg" => substr($rply,4));
mp-wp_genesis 209 if($this->do_debug >= 1) {
mp-wp_genesis 210 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 211 ": " . $rply . $this->CRLF;
mp-wp_genesis 212 }
mp-wp_genesis 213 return false;
mp-wp_genesis 214 }
mp-wp_genesis 215
mp-wp_genesis 216 return true;
mp-wp_genesis 217 }
mp-wp_genesis 218
mp-wp_genesis 219 /**
mp-wp_genesis 220 * Returns true if connected to a server otherwise false
mp-wp_genesis 221 * @access private
mp-wp_genesis 222 * @return bool
mp-wp_genesis 223 */
mp-wp_genesis 224 function Connected() {
mp-wp_genesis 225 if(!empty($this->smtp_conn)) {
mp-wp_genesis 226 $sock_status = socket_get_status($this->smtp_conn);
mp-wp_genesis 227 if($sock_status["eof"]) {
mp-wp_genesis 228 # hmm this is an odd situation... the socket is
mp-wp_genesis 229 # valid but we are not connected anymore
mp-wp_genesis 230 if($this->do_debug >= 1) {
mp-wp_genesis 231 echo "SMTP -> NOTICE:" . $this->CRLF .
mp-wp_genesis 232 "EOF caught while checking if connected";
mp-wp_genesis 233 }
mp-wp_genesis 234 $this->Close();
mp-wp_genesis 235 return false;
mp-wp_genesis 236 }
mp-wp_genesis 237 return true; # everything looks good
mp-wp_genesis 238 }
mp-wp_genesis 239 return false;
mp-wp_genesis 240 }
mp-wp_genesis 241
mp-wp_genesis 242 /**
mp-wp_genesis 243 * Closes the socket and cleans up the state of the class.
mp-wp_genesis 244 * It is not considered good to use this function without
mp-wp_genesis 245 * first trying to use QUIT.
mp-wp_genesis 246 * @access public
mp-wp_genesis 247 * @return void
mp-wp_genesis 248 */
mp-wp_genesis 249 function Close() {
mp-wp_genesis 250 $this->error = null; # so there is no confusion
mp-wp_genesis 251 $this->helo_rply = null;
mp-wp_genesis 252 if(!empty($this->smtp_conn)) {
mp-wp_genesis 253 # close the connection and cleanup
mp-wp_genesis 254 fclose($this->smtp_conn);
mp-wp_genesis 255 $this->smtp_conn = 0;
mp-wp_genesis 256 }
mp-wp_genesis 257 }
mp-wp_genesis 258
mp-wp_genesis 259 /***************************************************************
mp-wp_genesis 260 * SMTP COMMANDS *
mp-wp_genesis 261 *************************************************************/
mp-wp_genesis 262
mp-wp_genesis 263 /**
mp-wp_genesis 264 * Issues a data command and sends the msg_data to the server
mp-wp_genesis 265 * finializing the mail transaction. $msg_data is the message
mp-wp_genesis 266 * that is to be send with the headers. Each header needs to be
mp-wp_genesis 267 * on a single line followed by a <CRLF> with the message headers
mp-wp_genesis 268 * and the message body being seperated by and additional <CRLF>.
mp-wp_genesis 269 *
mp-wp_genesis 270 * Implements rfc 821: DATA <CRLF>
mp-wp_genesis 271 *
mp-wp_genesis 272 * SMTP CODE INTERMEDIATE: 354
mp-wp_genesis 273 * [data]
mp-wp_genesis 274 * <CRLF>.<CRLF>
mp-wp_genesis 275 * SMTP CODE SUCCESS: 250
mp-wp_genesis 276 * SMTP CODE FAILURE: 552,554,451,452
mp-wp_genesis 277 * SMTP CODE FAILURE: 451,554
mp-wp_genesis 278 * SMTP CODE ERROR : 500,501,503,421
mp-wp_genesis 279 * @access public
mp-wp_genesis 280 * @return bool
mp-wp_genesis 281 */
mp-wp_genesis 282 function Data($msg_data) {
mp-wp_genesis 283 $this->error = null; # so no confusion is caused
mp-wp_genesis 284
mp-wp_genesis 285 if(!$this->connected()) {
mp-wp_genesis 286 $this->error = array(
mp-wp_genesis 287 "error" => "Called Data() without being connected");
mp-wp_genesis 288 return false;
mp-wp_genesis 289 }
mp-wp_genesis 290
mp-wp_genesis 291 fputs($this->smtp_conn,"DATA" . $this->CRLF);
mp-wp_genesis 292
mp-wp_genesis 293 $rply = $this->get_lines();
mp-wp_genesis 294 $code = substr($rply,0,3);
mp-wp_genesis 295
mp-wp_genesis 296 if($this->do_debug >= 2) {
mp-wp_genesis 297 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 298 }
mp-wp_genesis 299
mp-wp_genesis 300 if($code != 354) {
mp-wp_genesis 301 $this->error =
mp-wp_genesis 302 array("error" => "DATA command not accepted from server",
mp-wp_genesis 303 "smtp_code" => $code,
mp-wp_genesis 304 "smtp_msg" => substr($rply,4));
mp-wp_genesis 305 if($this->do_debug >= 1) {
mp-wp_genesis 306 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 307 ": " . $rply . $this->CRLF;
mp-wp_genesis 308 }
mp-wp_genesis 309 return false;
mp-wp_genesis 310 }
mp-wp_genesis 311
mp-wp_genesis 312 # the server is ready to accept data!
mp-wp_genesis 313 # according to rfc 821 we should not send more than 1000
mp-wp_genesis 314 # including the CRLF
mp-wp_genesis 315 # characters on a single line so we will break the data up
mp-wp_genesis 316 # into lines by \r and/or \n then if needed we will break
mp-wp_genesis 317 # each of those into smaller lines to fit within the limit.
mp-wp_genesis 318 # in addition we will be looking for lines that start with
mp-wp_genesis 319 # a period '.' and append and additional period '.' to that
mp-wp_genesis 320 # line. NOTE: this does not count towards are limit.
mp-wp_genesis 321
mp-wp_genesis 322 # normalize the line breaks so we know the explode works
mp-wp_genesis 323 $msg_data = str_replace("\r\n","\n",$msg_data);
mp-wp_genesis 324 $msg_data = str_replace("\r","\n",$msg_data);
mp-wp_genesis 325 $lines = explode("\n",$msg_data);
mp-wp_genesis 326
mp-wp_genesis 327 # we need to find a good way to determine is headers are
mp-wp_genesis 328 # in the msg_data or if it is a straight msg body
mp-wp_genesis 329 # currently I am assuming rfc 822 definitions of msg headers
mp-wp_genesis 330 # and if the first field of the first line (':' sperated)
mp-wp_genesis 331 # does not contain a space then it _should_ be a header
mp-wp_genesis 332 # and we can process all lines before a blank "" line as
mp-wp_genesis 333 # headers.
mp-wp_genesis 334 $field = substr($lines[0],0,strpos($lines[0],":"));
mp-wp_genesis 335 $in_headers = false;
mp-wp_genesis 336 if(!empty($field) && !strstr($field," ")) {
mp-wp_genesis 337 $in_headers = true;
mp-wp_genesis 338 }
mp-wp_genesis 339
mp-wp_genesis 340 $max_line_length = 998; # used below; set here for ease in change
mp-wp_genesis 341
mp-wp_genesis 342 while(list(,$line) = @each($lines)) {
mp-wp_genesis 343 $lines_out = null;
mp-wp_genesis 344 if($line == "" && $in_headers) {
mp-wp_genesis 345 $in_headers = false;
mp-wp_genesis 346 }
mp-wp_genesis 347 # ok we need to break this line up into several
mp-wp_genesis 348 # smaller lines
mp-wp_genesis 349 while(strlen($line) > $max_line_length) {
mp-wp_genesis 350 $pos = strrpos(substr($line,0,$max_line_length)," ");
mp-wp_genesis 351
mp-wp_genesis 352 # Patch to fix DOS attack
mp-wp_genesis 353 if(!$pos) {
mp-wp_genesis 354 $pos = $max_line_length - 1;
mp-wp_genesis 355 }
mp-wp_genesis 356
mp-wp_genesis 357 $lines_out[] = substr($line,0,$pos);
mp-wp_genesis 358 $line = substr($line,$pos + 1);
mp-wp_genesis 359 # if we are processing headers we need to
mp-wp_genesis 360 # add a LWSP-char to the front of the new line
mp-wp_genesis 361 # rfc 822 on long msg headers
mp-wp_genesis 362 if($in_headers) {
mp-wp_genesis 363 $line = "\t" . $line;
mp-wp_genesis 364 }
mp-wp_genesis 365 }
mp-wp_genesis 366 $lines_out[] = $line;
mp-wp_genesis 367
mp-wp_genesis 368 # now send the lines to the server
mp-wp_genesis 369 while(list(,$line_out) = @each($lines_out)) {
mp-wp_genesis 370 if(strlen($line_out) > 0)
mp-wp_genesis 371 {
mp-wp_genesis 372 if(substr($line_out, 0, 1) == ".") {
mp-wp_genesis 373 $line_out = "." . $line_out;
mp-wp_genesis 374 }
mp-wp_genesis 375 }
mp-wp_genesis 376 fputs($this->smtp_conn,$line_out . $this->CRLF);
mp-wp_genesis 377 }
mp-wp_genesis 378 }
mp-wp_genesis 379
mp-wp_genesis 380 # ok all the message data has been sent so lets get this
mp-wp_genesis 381 # over with aleady
mp-wp_genesis 382 fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
mp-wp_genesis 383
mp-wp_genesis 384 $rply = $this->get_lines();
mp-wp_genesis 385 $code = substr($rply,0,3);
mp-wp_genesis 386
mp-wp_genesis 387 if($this->do_debug >= 2) {
mp-wp_genesis 388 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 389 }
mp-wp_genesis 390
mp-wp_genesis 391 if($code != 250) {
mp-wp_genesis 392 $this->error =
mp-wp_genesis 393 array("error" => "DATA not accepted from server",
mp-wp_genesis 394 "smtp_code" => $code,
mp-wp_genesis 395 "smtp_msg" => substr($rply,4));
mp-wp_genesis 396 if($this->do_debug >= 1) {
mp-wp_genesis 397 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 398 ": " . $rply . $this->CRLF;
mp-wp_genesis 399 }
mp-wp_genesis 400 return false;
mp-wp_genesis 401 }
mp-wp_genesis 402 return true;
mp-wp_genesis 403 }
mp-wp_genesis 404
mp-wp_genesis 405 /**
mp-wp_genesis 406 * Expand takes the name and asks the server to list all the
mp-wp_genesis 407 * people who are members of the _list_. Expand will return
mp-wp_genesis 408 * back and array of the result or false if an error occurs.
mp-wp_genesis 409 * Each value in the array returned has the format of:
mp-wp_genesis 410 * [ <full-name> <sp> ] <path>
mp-wp_genesis 411 * The definition of <path> is defined in rfc 821
mp-wp_genesis 412 *
mp-wp_genesis 413 * Implements rfc 821: EXPN <SP> <string> <CRLF>
mp-wp_genesis 414 *
mp-wp_genesis 415 * SMTP CODE SUCCESS: 250
mp-wp_genesis 416 * SMTP CODE FAILURE: 550
mp-wp_genesis 417 * SMTP CODE ERROR : 500,501,502,504,421
mp-wp_genesis 418 * @access public
mp-wp_genesis 419 * @return string array
mp-wp_genesis 420 */
mp-wp_genesis 421 function Expand($name) {
mp-wp_genesis 422 $this->error = null; # so no confusion is caused
mp-wp_genesis 423
mp-wp_genesis 424 if(!$this->connected()) {
mp-wp_genesis 425 $this->error = array(
mp-wp_genesis 426 "error" => "Called Expand() without being connected");
mp-wp_genesis 427 return false;
mp-wp_genesis 428 }
mp-wp_genesis 429
mp-wp_genesis 430 fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
mp-wp_genesis 431
mp-wp_genesis 432 $rply = $this->get_lines();
mp-wp_genesis 433 $code = substr($rply,0,3);
mp-wp_genesis 434
mp-wp_genesis 435 if($this->do_debug >= 2) {
mp-wp_genesis 436 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 437 }
mp-wp_genesis 438
mp-wp_genesis 439 if($code != 250) {
mp-wp_genesis 440 $this->error =
mp-wp_genesis 441 array("error" => "EXPN not accepted from server",
mp-wp_genesis 442 "smtp_code" => $code,
mp-wp_genesis 443 "smtp_msg" => substr($rply,4));
mp-wp_genesis 444 if($this->do_debug >= 1) {
mp-wp_genesis 445 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 446 ": " . $rply . $this->CRLF;
mp-wp_genesis 447 }
mp-wp_genesis 448 return false;
mp-wp_genesis 449 }
mp-wp_genesis 450
mp-wp_genesis 451 # parse the reply and place in our array to return to user
mp-wp_genesis 452 $entries = explode($this->CRLF,$rply);
mp-wp_genesis 453 while(list(,$l) = @each($entries)) {
mp-wp_genesis 454 $list[] = substr($l,4);
mp-wp_genesis 455 }
mp-wp_genesis 456
mp-wp_genesis 457 return $list;
mp-wp_genesis 458 }
mp-wp_genesis 459
mp-wp_genesis 460 /**
mp-wp_genesis 461 * Sends the HELO command to the smtp server.
mp-wp_genesis 462 * This makes sure that we and the server are in
mp-wp_genesis 463 * the same known state.
mp-wp_genesis 464 *
mp-wp_genesis 465 * Implements from rfc 821: HELO <SP> <domain> <CRLF>
mp-wp_genesis 466 *
mp-wp_genesis 467 * SMTP CODE SUCCESS: 250
mp-wp_genesis 468 * SMTP CODE ERROR : 500, 501, 504, 421
mp-wp_genesis 469 * @access public
mp-wp_genesis 470 * @return bool
mp-wp_genesis 471 */
mp-wp_genesis 472 function Hello($host="") {
mp-wp_genesis 473 $this->error = null; # so no confusion is caused
mp-wp_genesis 474
mp-wp_genesis 475 if(!$this->connected()) {
mp-wp_genesis 476 $this->error = array(
mp-wp_genesis 477 "error" => "Called Hello() without being connected");
mp-wp_genesis 478 return false;
mp-wp_genesis 479 }
mp-wp_genesis 480
mp-wp_genesis 481 # if a hostname for the HELO was not specified determine
mp-wp_genesis 482 # a suitable one to send
mp-wp_genesis 483 if(empty($host)) {
mp-wp_genesis 484 # we need to determine some sort of appopiate default
mp-wp_genesis 485 # to send to the server
mp-wp_genesis 486 $host = "localhost";
mp-wp_genesis 487 }
mp-wp_genesis 488
mp-wp_genesis 489 // Send extended hello first (RFC 2821)
mp-wp_genesis 490 if(!$this->SendHello("EHLO", $host))
mp-wp_genesis 491 {
mp-wp_genesis 492 if(!$this->SendHello("HELO", $host))
mp-wp_genesis 493 return false;
mp-wp_genesis 494 }
mp-wp_genesis 495
mp-wp_genesis 496 return true;
mp-wp_genesis 497 }
mp-wp_genesis 498
mp-wp_genesis 499 /**
mp-wp_genesis 500 * Sends a HELO/EHLO command.
mp-wp_genesis 501 * @access private
mp-wp_genesis 502 * @return bool
mp-wp_genesis 503 */
mp-wp_genesis 504 function SendHello($hello, $host) {
mp-wp_genesis 505 fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
mp-wp_genesis 506
mp-wp_genesis 507 $rply = $this->get_lines();
mp-wp_genesis 508 $code = substr($rply,0,3);
mp-wp_genesis 509
mp-wp_genesis 510 if($this->do_debug >= 2) {
mp-wp_genesis 511 echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
mp-wp_genesis 512 }
mp-wp_genesis 513
mp-wp_genesis 514 if($code != 250) {
mp-wp_genesis 515 $this->error =
mp-wp_genesis 516 array("error" => $hello . " not accepted from server",
mp-wp_genesis 517 "smtp_code" => $code,
mp-wp_genesis 518 "smtp_msg" => substr($rply,4));
mp-wp_genesis 519 if($this->do_debug >= 1) {
mp-wp_genesis 520 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 521 ": " . $rply . $this->CRLF;
mp-wp_genesis 522 }
mp-wp_genesis 523 return false;
mp-wp_genesis 524 }
mp-wp_genesis 525
mp-wp_genesis 526 $this->helo_rply = $rply;
mp-wp_genesis 527
mp-wp_genesis 528 return true;
mp-wp_genesis 529 }
mp-wp_genesis 530
mp-wp_genesis 531 /**
mp-wp_genesis 532 * Gets help information on the keyword specified. If the keyword
mp-wp_genesis 533 * is not specified then returns generic help, ussually contianing
mp-wp_genesis 534 * A list of keywords that help is available on. This function
mp-wp_genesis 535 * returns the results back to the user. It is up to the user to
mp-wp_genesis 536 * handle the returned data. If an error occurs then false is
mp-wp_genesis 537 * returned with $this->error set appropiately.
mp-wp_genesis 538 *
mp-wp_genesis 539 * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
mp-wp_genesis 540 *
mp-wp_genesis 541 * SMTP CODE SUCCESS: 211,214
mp-wp_genesis 542 * SMTP CODE ERROR : 500,501,502,504,421
mp-wp_genesis 543 * @access public
mp-wp_genesis 544 * @return string
mp-wp_genesis 545 */
mp-wp_genesis 546 function Help($keyword="") {
mp-wp_genesis 547 $this->error = null; # to avoid confusion
mp-wp_genesis 548
mp-wp_genesis 549 if(!$this->connected()) {
mp-wp_genesis 550 $this->error = array(
mp-wp_genesis 551 "error" => "Called Help() without being connected");
mp-wp_genesis 552 return false;
mp-wp_genesis 553 }
mp-wp_genesis 554
mp-wp_genesis 555 $extra = "";
mp-wp_genesis 556 if(!empty($keyword)) {
mp-wp_genesis 557 $extra = " " . $keyword;
mp-wp_genesis 558 }
mp-wp_genesis 559
mp-wp_genesis 560 fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
mp-wp_genesis 561
mp-wp_genesis 562 $rply = $this->get_lines();
mp-wp_genesis 563 $code = substr($rply,0,3);
mp-wp_genesis 564
mp-wp_genesis 565 if($this->do_debug >= 2) {
mp-wp_genesis 566 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 567 }
mp-wp_genesis 568
mp-wp_genesis 569 if($code != 211 && $code != 214) {
mp-wp_genesis 570 $this->error =
mp-wp_genesis 571 array("error" => "HELP not accepted from server",
mp-wp_genesis 572 "smtp_code" => $code,
mp-wp_genesis 573 "smtp_msg" => substr($rply,4));
mp-wp_genesis 574 if($this->do_debug >= 1) {
mp-wp_genesis 575 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 576 ": " . $rply . $this->CRLF;
mp-wp_genesis 577 }
mp-wp_genesis 578 return false;
mp-wp_genesis 579 }
mp-wp_genesis 580
mp-wp_genesis 581 return $rply;
mp-wp_genesis 582 }
mp-wp_genesis 583
mp-wp_genesis 584 /**
mp-wp_genesis 585 * Starts a mail transaction from the email address specified in
mp-wp_genesis 586 * $from. Returns true if successful or false otherwise. If True
mp-wp_genesis 587 * the mail transaction is started and then one or more Recipient
mp-wp_genesis 588 * commands may be called followed by a Data command.
mp-wp_genesis 589 *
mp-wp_genesis 590 * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
mp-wp_genesis 591 *
mp-wp_genesis 592 * SMTP CODE SUCCESS: 250
mp-wp_genesis 593 * SMTP CODE SUCCESS: 552,451,452
mp-wp_genesis 594 * SMTP CODE SUCCESS: 500,501,421
mp-wp_genesis 595 * @access public
mp-wp_genesis 596 * @return bool
mp-wp_genesis 597 */
mp-wp_genesis 598 function Mail($from) {
mp-wp_genesis 599 $this->error = null; # so no confusion is caused
mp-wp_genesis 600
mp-wp_genesis 601 if(!$this->connected()) {
mp-wp_genesis 602 $this->error = array(
mp-wp_genesis 603 "error" => "Called Mail() without being connected");
mp-wp_genesis 604 return false;
mp-wp_genesis 605 }
mp-wp_genesis 606
mp-wp_genesis 607 $useVerp = ($this->do_verp ? "XVERP" : "");
mp-wp_genesis 608 fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
mp-wp_genesis 609
mp-wp_genesis 610 $rply = $this->get_lines();
mp-wp_genesis 611 $code = substr($rply,0,3);
mp-wp_genesis 612
mp-wp_genesis 613 if($this->do_debug >= 2) {
mp-wp_genesis 614 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 615 }
mp-wp_genesis 616
mp-wp_genesis 617 if($code != 250) {
mp-wp_genesis 618 $this->error =
mp-wp_genesis 619 array("error" => "MAIL not accepted from server",
mp-wp_genesis 620 "smtp_code" => $code,
mp-wp_genesis 621 "smtp_msg" => substr($rply,4));
mp-wp_genesis 622 if($this->do_debug >= 1) {
mp-wp_genesis 623 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 624 ": " . $rply . $this->CRLF;
mp-wp_genesis 625 }
mp-wp_genesis 626 return false;
mp-wp_genesis 627 }
mp-wp_genesis 628 return true;
mp-wp_genesis 629 }
mp-wp_genesis 630
mp-wp_genesis 631 /**
mp-wp_genesis 632 * Sends the command NOOP to the SMTP server.
mp-wp_genesis 633 *
mp-wp_genesis 634 * Implements from rfc 821: NOOP <CRLF>
mp-wp_genesis 635 *
mp-wp_genesis 636 * SMTP CODE SUCCESS: 250
mp-wp_genesis 637 * SMTP CODE ERROR : 500, 421
mp-wp_genesis 638 * @access public
mp-wp_genesis 639 * @return bool
mp-wp_genesis 640 */
mp-wp_genesis 641 function Noop() {
mp-wp_genesis 642 $this->error = null; # so no confusion is caused
mp-wp_genesis 643
mp-wp_genesis 644 if(!$this->connected()) {
mp-wp_genesis 645 $this->error = array(
mp-wp_genesis 646 "error" => "Called Noop() without being connected");
mp-wp_genesis 647 return false;
mp-wp_genesis 648 }
mp-wp_genesis 649
mp-wp_genesis 650 fputs($this->smtp_conn,"NOOP" . $this->CRLF);
mp-wp_genesis 651
mp-wp_genesis 652 $rply = $this->get_lines();
mp-wp_genesis 653 $code = substr($rply,0,3);
mp-wp_genesis 654
mp-wp_genesis 655 if($this->do_debug >= 2) {
mp-wp_genesis 656 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 657 }
mp-wp_genesis 658
mp-wp_genesis 659 if($code != 250) {
mp-wp_genesis 660 $this->error =
mp-wp_genesis 661 array("error" => "NOOP not accepted from server",
mp-wp_genesis 662 "smtp_code" => $code,
mp-wp_genesis 663 "smtp_msg" => substr($rply,4));
mp-wp_genesis 664 if($this->do_debug >= 1) {
mp-wp_genesis 665 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 666 ": " . $rply . $this->CRLF;
mp-wp_genesis 667 }
mp-wp_genesis 668 return false;
mp-wp_genesis 669 }
mp-wp_genesis 670 return true;
mp-wp_genesis 671 }
mp-wp_genesis 672
mp-wp_genesis 673 /**
mp-wp_genesis 674 * Sends the quit command to the server and then closes the socket
mp-wp_genesis 675 * if there is no error or the $close_on_error argument is true.
mp-wp_genesis 676 *
mp-wp_genesis 677 * Implements from rfc 821: QUIT <CRLF>
mp-wp_genesis 678 *
mp-wp_genesis 679 * SMTP CODE SUCCESS: 221
mp-wp_genesis 680 * SMTP CODE ERROR : 500
mp-wp_genesis 681 * @access public
mp-wp_genesis 682 * @return bool
mp-wp_genesis 683 */
mp-wp_genesis 684 function Quit($close_on_error=true) {
mp-wp_genesis 685 $this->error = null; # so there is no confusion
mp-wp_genesis 686
mp-wp_genesis 687 if(!$this->connected()) {
mp-wp_genesis 688 $this->error = array(
mp-wp_genesis 689 "error" => "Called Quit() without being connected");
mp-wp_genesis 690 return false;
mp-wp_genesis 691 }
mp-wp_genesis 692
mp-wp_genesis 693 # send the quit command to the server
mp-wp_genesis 694 fputs($this->smtp_conn,"quit" . $this->CRLF);
mp-wp_genesis 695
mp-wp_genesis 696 # get any good-bye messages
mp-wp_genesis 697 $byemsg = $this->get_lines();
mp-wp_genesis 698
mp-wp_genesis 699 if($this->do_debug >= 2) {
mp-wp_genesis 700 echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
mp-wp_genesis 701 }
mp-wp_genesis 702
mp-wp_genesis 703 $rval = true;
mp-wp_genesis 704 $e = null;
mp-wp_genesis 705
mp-wp_genesis 706 $code = substr($byemsg,0,3);
mp-wp_genesis 707 if($code != 221) {
mp-wp_genesis 708 # use e as a tmp var cause Close will overwrite $this->error
mp-wp_genesis 709 $e = array("error" => "SMTP server rejected quit command",
mp-wp_genesis 710 "smtp_code" => $code,
mp-wp_genesis 711 "smtp_rply" => substr($byemsg,4));
mp-wp_genesis 712 $rval = false;
mp-wp_genesis 713 if($this->do_debug >= 1) {
mp-wp_genesis 714 echo "SMTP -> ERROR: " . $e["error"] . ": " .
mp-wp_genesis 715 $byemsg . $this->CRLF;
mp-wp_genesis 716 }
mp-wp_genesis 717 }
mp-wp_genesis 718
mp-wp_genesis 719 if(empty($e) || $close_on_error) {
mp-wp_genesis 720 $this->Close();
mp-wp_genesis 721 }
mp-wp_genesis 722
mp-wp_genesis 723 return $rval;
mp-wp_genesis 724 }
mp-wp_genesis 725
mp-wp_genesis 726 /**
mp-wp_genesis 727 * Sends the command RCPT to the SMTP server with the TO: argument of $to.
mp-wp_genesis 728 * Returns true if the recipient was accepted false if it was rejected.
mp-wp_genesis 729 *
mp-wp_genesis 730 * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
mp-wp_genesis 731 *
mp-wp_genesis 732 * SMTP CODE SUCCESS: 250,251
mp-wp_genesis 733 * SMTP CODE FAILURE: 550,551,552,553,450,451,452
mp-wp_genesis 734 * SMTP CODE ERROR : 500,501,503,421
mp-wp_genesis 735 * @access public
mp-wp_genesis 736 * @return bool
mp-wp_genesis 737 */
mp-wp_genesis 738 function Recipient($to) {
mp-wp_genesis 739 $this->error = null; # so no confusion is caused
mp-wp_genesis 740
mp-wp_genesis 741 if(!$this->connected()) {
mp-wp_genesis 742 $this->error = array(
mp-wp_genesis 743 "error" => "Called Recipient() without being connected");
mp-wp_genesis 744 return false;
mp-wp_genesis 745 }
mp-wp_genesis 746
mp-wp_genesis 747 fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
mp-wp_genesis 748
mp-wp_genesis 749 $rply = $this->get_lines();
mp-wp_genesis 750 $code = substr($rply,0,3);
mp-wp_genesis 751
mp-wp_genesis 752 if($this->do_debug >= 2) {
mp-wp_genesis 753 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 754 }
mp-wp_genesis 755
mp-wp_genesis 756 if($code != 250 && $code != 251) {
mp-wp_genesis 757 $this->error =
mp-wp_genesis 758 array("error" => "RCPT not accepted from server",
mp-wp_genesis 759 "smtp_code" => $code,
mp-wp_genesis 760 "smtp_msg" => substr($rply,4));
mp-wp_genesis 761 if($this->do_debug >= 1) {
mp-wp_genesis 762 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 763 ": " . $rply . $this->CRLF;
mp-wp_genesis 764 }
mp-wp_genesis 765 return false;
mp-wp_genesis 766 }
mp-wp_genesis 767 return true;
mp-wp_genesis 768 }
mp-wp_genesis 769
mp-wp_genesis 770 /**
mp-wp_genesis 771 * Sends the RSET command to abort and transaction that is
mp-wp_genesis 772 * currently in progress. Returns true if successful false
mp-wp_genesis 773 * otherwise.
mp-wp_genesis 774 *
mp-wp_genesis 775 * Implements rfc 821: RSET <CRLF>
mp-wp_genesis 776 *
mp-wp_genesis 777 * SMTP CODE SUCCESS: 250
mp-wp_genesis 778 * SMTP CODE ERROR : 500,501,504,421
mp-wp_genesis 779 * @access public
mp-wp_genesis 780 * @return bool
mp-wp_genesis 781 */
mp-wp_genesis 782 function Reset() {
mp-wp_genesis 783 $this->error = null; # so no confusion is caused
mp-wp_genesis 784
mp-wp_genesis 785 if(!$this->connected()) {
mp-wp_genesis 786 $this->error = array(
mp-wp_genesis 787 "error" => "Called Reset() without being connected");
mp-wp_genesis 788 return false;
mp-wp_genesis 789 }
mp-wp_genesis 790
mp-wp_genesis 791 fputs($this->smtp_conn,"RSET" . $this->CRLF);
mp-wp_genesis 792
mp-wp_genesis 793 $rply = $this->get_lines();
mp-wp_genesis 794 $code = substr($rply,0,3);
mp-wp_genesis 795
mp-wp_genesis 796 if($this->do_debug >= 2) {
mp-wp_genesis 797 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 798 }
mp-wp_genesis 799
mp-wp_genesis 800 if($code != 250) {
mp-wp_genesis 801 $this->error =
mp-wp_genesis 802 array("error" => "RSET failed",
mp-wp_genesis 803 "smtp_code" => $code,
mp-wp_genesis 804 "smtp_msg" => substr($rply,4));
mp-wp_genesis 805 if($this->do_debug >= 1) {
mp-wp_genesis 806 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 807 ": " . $rply . $this->CRLF;
mp-wp_genesis 808 }
mp-wp_genesis 809 return false;
mp-wp_genesis 810 }
mp-wp_genesis 811
mp-wp_genesis 812 return true;
mp-wp_genesis 813 }
mp-wp_genesis 814
mp-wp_genesis 815 /**
mp-wp_genesis 816 * Starts a mail transaction from the email address specified in
mp-wp_genesis 817 * $from. Returns true if successful or false otherwise. If True
mp-wp_genesis 818 * the mail transaction is started and then one or more Recipient
mp-wp_genesis 819 * commands may be called followed by a Data command. This command
mp-wp_genesis 820 * will send the message to the users terminal if they are logged
mp-wp_genesis 821 * in.
mp-wp_genesis 822 *
mp-wp_genesis 823 * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
mp-wp_genesis 824 *
mp-wp_genesis 825 * SMTP CODE SUCCESS: 250
mp-wp_genesis 826 * SMTP CODE SUCCESS: 552,451,452
mp-wp_genesis 827 * SMTP CODE SUCCESS: 500,501,502,421
mp-wp_genesis 828 * @access public
mp-wp_genesis 829 * @return bool
mp-wp_genesis 830 */
mp-wp_genesis 831 function Send($from) {
mp-wp_genesis 832 $this->error = null; # so no confusion is caused
mp-wp_genesis 833
mp-wp_genesis 834 if(!$this->connected()) {
mp-wp_genesis 835 $this->error = array(
mp-wp_genesis 836 "error" => "Called Send() without being connected");
mp-wp_genesis 837 return false;
mp-wp_genesis 838 }
mp-wp_genesis 839
mp-wp_genesis 840 fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
mp-wp_genesis 841
mp-wp_genesis 842 $rply = $this->get_lines();
mp-wp_genesis 843 $code = substr($rply,0,3);
mp-wp_genesis 844
mp-wp_genesis 845 if($this->do_debug >= 2) {
mp-wp_genesis 846 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 847 }
mp-wp_genesis 848
mp-wp_genesis 849 if($code != 250) {
mp-wp_genesis 850 $this->error =
mp-wp_genesis 851 array("error" => "SEND not accepted from server",
mp-wp_genesis 852 "smtp_code" => $code,
mp-wp_genesis 853 "smtp_msg" => substr($rply,4));
mp-wp_genesis 854 if($this->do_debug >= 1) {
mp-wp_genesis 855 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 856 ": " . $rply . $this->CRLF;
mp-wp_genesis 857 }
mp-wp_genesis 858 return false;
mp-wp_genesis 859 }
mp-wp_genesis 860 return true;
mp-wp_genesis 861 }
mp-wp_genesis 862
mp-wp_genesis 863 /**
mp-wp_genesis 864 * Starts a mail transaction from the email address specified in
mp-wp_genesis 865 * $from. Returns true if successful or false otherwise. If True
mp-wp_genesis 866 * the mail transaction is started and then one or more Recipient
mp-wp_genesis 867 * commands may be called followed by a Data command. This command
mp-wp_genesis 868 * will send the message to the users terminal if they are logged
mp-wp_genesis 869 * in and send them an email.
mp-wp_genesis 870 *
mp-wp_genesis 871 * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
mp-wp_genesis 872 *
mp-wp_genesis 873 * SMTP CODE SUCCESS: 250
mp-wp_genesis 874 * SMTP CODE SUCCESS: 552,451,452
mp-wp_genesis 875 * SMTP CODE SUCCESS: 500,501,502,421
mp-wp_genesis 876 * @access public
mp-wp_genesis 877 * @return bool
mp-wp_genesis 878 */
mp-wp_genesis 879 function SendAndMail($from) {
mp-wp_genesis 880 $this->error = null; # so no confusion is caused
mp-wp_genesis 881
mp-wp_genesis 882 if(!$this->connected()) {
mp-wp_genesis 883 $this->error = array(
mp-wp_genesis 884 "error" => "Called SendAndMail() without being connected");
mp-wp_genesis 885 return false;
mp-wp_genesis 886 }
mp-wp_genesis 887
mp-wp_genesis 888 fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
mp-wp_genesis 889
mp-wp_genesis 890 $rply = $this->get_lines();
mp-wp_genesis 891 $code = substr($rply,0,3);
mp-wp_genesis 892
mp-wp_genesis 893 if($this->do_debug >= 2) {
mp-wp_genesis 894 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 895 }
mp-wp_genesis 896
mp-wp_genesis 897 if($code != 250) {
mp-wp_genesis 898 $this->error =
mp-wp_genesis 899 array("error" => "SAML not accepted from server",
mp-wp_genesis 900 "smtp_code" => $code,
mp-wp_genesis 901 "smtp_msg" => substr($rply,4));
mp-wp_genesis 902 if($this->do_debug >= 1) {
mp-wp_genesis 903 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 904 ": " . $rply . $this->CRLF;
mp-wp_genesis 905 }
mp-wp_genesis 906 return false;
mp-wp_genesis 907 }
mp-wp_genesis 908 return true;
mp-wp_genesis 909 }
mp-wp_genesis 910
mp-wp_genesis 911 /**
mp-wp_genesis 912 * Starts a mail transaction from the email address specified in
mp-wp_genesis 913 * $from. Returns true if successful or false otherwise. If True
mp-wp_genesis 914 * the mail transaction is started and then one or more Recipient
mp-wp_genesis 915 * commands may be called followed by a Data command. This command
mp-wp_genesis 916 * will send the message to the users terminal if they are logged
mp-wp_genesis 917 * in or mail it to them if they are not.
mp-wp_genesis 918 *
mp-wp_genesis 919 * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
mp-wp_genesis 920 *
mp-wp_genesis 921 * SMTP CODE SUCCESS: 250
mp-wp_genesis 922 * SMTP CODE SUCCESS: 552,451,452
mp-wp_genesis 923 * SMTP CODE SUCCESS: 500,501,502,421
mp-wp_genesis 924 * @access public
mp-wp_genesis 925 * @return bool
mp-wp_genesis 926 */
mp-wp_genesis 927 function SendOrMail($from) {
mp-wp_genesis 928 $this->error = null; # so no confusion is caused
mp-wp_genesis 929
mp-wp_genesis 930 if(!$this->connected()) {
mp-wp_genesis 931 $this->error = array(
mp-wp_genesis 932 "error" => "Called SendOrMail() without being connected");
mp-wp_genesis 933 return false;
mp-wp_genesis 934 }
mp-wp_genesis 935
mp-wp_genesis 936 fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
mp-wp_genesis 937
mp-wp_genesis 938 $rply = $this->get_lines();
mp-wp_genesis 939 $code = substr($rply,0,3);
mp-wp_genesis 940
mp-wp_genesis 941 if($this->do_debug >= 2) {
mp-wp_genesis 942 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 943 }
mp-wp_genesis 944
mp-wp_genesis 945 if($code != 250) {
mp-wp_genesis 946 $this->error =
mp-wp_genesis 947 array("error" => "SOML not accepted from server",
mp-wp_genesis 948 "smtp_code" => $code,
mp-wp_genesis 949 "smtp_msg" => substr($rply,4));
mp-wp_genesis 950 if($this->do_debug >= 1) {
mp-wp_genesis 951 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 952 ": " . $rply . $this->CRLF;
mp-wp_genesis 953 }
mp-wp_genesis 954 return false;
mp-wp_genesis 955 }
mp-wp_genesis 956 return true;
mp-wp_genesis 957 }
mp-wp_genesis 958
mp-wp_genesis 959 /**
mp-wp_genesis 960 * This is an optional command for SMTP that this class does not
mp-wp_genesis 961 * support. This method is here to make the RFC821 Definition
mp-wp_genesis 962 * complete for this class and __may__ be implimented in the future
mp-wp_genesis 963 *
mp-wp_genesis 964 * Implements from rfc 821: TURN <CRLF>
mp-wp_genesis 965 *
mp-wp_genesis 966 * SMTP CODE SUCCESS: 250
mp-wp_genesis 967 * SMTP CODE FAILURE: 502
mp-wp_genesis 968 * SMTP CODE ERROR : 500, 503
mp-wp_genesis 969 * @access public
mp-wp_genesis 970 * @return bool
mp-wp_genesis 971 */
mp-wp_genesis 972 function Turn() {
mp-wp_genesis 973 $this->error = array("error" => "This method, TURN, of the SMTP ".
mp-wp_genesis 974 "is not implemented");
mp-wp_genesis 975 if($this->do_debug >= 1) {
mp-wp_genesis 976 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
mp-wp_genesis 977 }
mp-wp_genesis 978 return false;
mp-wp_genesis 979 }
mp-wp_genesis 980
mp-wp_genesis 981 /**
mp-wp_genesis 982 * Verifies that the name is recognized by the server.
mp-wp_genesis 983 * Returns false if the name could not be verified otherwise
mp-wp_genesis 984 * the response from the server is returned.
mp-wp_genesis 985 *
mp-wp_genesis 986 * Implements rfc 821: VRFY <SP> <string> <CRLF>
mp-wp_genesis 987 *
mp-wp_genesis 988 * SMTP CODE SUCCESS: 250,251
mp-wp_genesis 989 * SMTP CODE FAILURE: 550,551,553
mp-wp_genesis 990 * SMTP CODE ERROR : 500,501,502,421
mp-wp_genesis 991 * @access public
mp-wp_genesis 992 * @return int
mp-wp_genesis 993 */
mp-wp_genesis 994 function Verify($name) {
mp-wp_genesis 995 $this->error = null; # so no confusion is caused
mp-wp_genesis 996
mp-wp_genesis 997 if(!$this->connected()) {
mp-wp_genesis 998 $this->error = array(
mp-wp_genesis 999 "error" => "Called Verify() without being connected");
mp-wp_genesis 1000 return false;
mp-wp_genesis 1001 }
mp-wp_genesis 1002
mp-wp_genesis 1003 fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
mp-wp_genesis 1004
mp-wp_genesis 1005 $rply = $this->get_lines();
mp-wp_genesis 1006 $code = substr($rply,0,3);
mp-wp_genesis 1007
mp-wp_genesis 1008 if($this->do_debug >= 2) {
mp-wp_genesis 1009 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
mp-wp_genesis 1010 }
mp-wp_genesis 1011
mp-wp_genesis 1012 if($code != 250 && $code != 251) {
mp-wp_genesis 1013 $this->error =
mp-wp_genesis 1014 array("error" => "VRFY failed on name '$name'",
mp-wp_genesis 1015 "smtp_code" => $code,
mp-wp_genesis 1016 "smtp_msg" => substr($rply,4));
mp-wp_genesis 1017 if($this->do_debug >= 1) {
mp-wp_genesis 1018 echo "SMTP -> ERROR: " . $this->error["error"] .
mp-wp_genesis 1019 ": " . $rply . $this->CRLF;
mp-wp_genesis 1020 }
mp-wp_genesis 1021 return false;
mp-wp_genesis 1022 }
mp-wp_genesis 1023 return $rply;
mp-wp_genesis 1024 }
mp-wp_genesis 1025
mp-wp_genesis 1026 /*******************************************************************
mp-wp_genesis 1027 * INTERNAL FUNCTIONS *
mp-wp_genesis 1028 ******************************************************************/
mp-wp_genesis 1029
mp-wp_genesis 1030 /**
mp-wp_genesis 1031 * Read in as many lines as possible
mp-wp_genesis 1032 * either before eof or socket timeout occurs on the operation.
mp-wp_genesis 1033 * With SMTP we can tell if we have more lines to read if the
mp-wp_genesis 1034 * 4th character is '-' symbol. If it is a space then we don't
mp-wp_genesis 1035 * need to read anything else.
mp-wp_genesis 1036 * @access private
mp-wp_genesis 1037 * @return string
mp-wp_genesis 1038 */
mp-wp_genesis 1039 function get_lines() {
mp-wp_genesis 1040 $data = "";
mp-wp_genesis 1041 while($str = @fgets($this->smtp_conn,515)) {
mp-wp_genesis 1042 if($this->do_debug >= 4) {
mp-wp_genesis 1043 echo "SMTP -> get_lines(): \$data was \"$data\"" .
mp-wp_genesis 1044 $this->CRLF;
mp-wp_genesis 1045 echo "SMTP -> get_lines(): \$str is \"$str\"" .
mp-wp_genesis 1046 $this->CRLF;
mp-wp_genesis 1047 }
mp-wp_genesis 1048 $data .= $str;
mp-wp_genesis 1049 if($this->do_debug >= 4) {
mp-wp_genesis 1050 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
mp-wp_genesis 1051 }
mp-wp_genesis 1052 # if the 4th character is a space then we are done reading
mp-wp_genesis 1053 # so just break the loop
mp-wp_genesis 1054 if(substr($str,3,1) == " ") { break; }
mp-wp_genesis 1055 }
mp-wp_genesis 1056 return $data;
mp-wp_genesis 1057 }
mp-wp_genesis 1058
mp-wp_genesis 1059 }
mp-wp_genesis 1060
mp-wp_genesis 1061
mp-wp_genesis 1062 ?>