phpBugTracker PHP Cross Reference Customer Relationship Management

Source: /inc/htmlMimeMail/htmlMimeMail.php - 778 lines - 20193 bytes - Summary - Text - Print

Description: Filename.......: class.html.mime.mail.inc Project........: HTML Mime mail class Last Modified..: Date: 2002/07/24 13:14:10 CVS Revision...: Revision: 1.4 Copyright......: 2001, 2002 Richard Heyes

   1  <?php
   2  /**
   3  * Filename.......: class.html.mime.mail.inc
   4  * Project........: HTML Mime mail class
   5  * Last Modified..: Date: 2002/07/24 13:14:10
   6  * CVS Revision...: Revision: 1.4
   7  * Copyright......: 2001, 2002 Richard Heyes
   8  */
   9  
  10  require_once(dirname(__FILE__) . '/mimePart.php');
  11  
  12  class htmlMimeMail
  13  {
  14      /**
  15      * The html part of the message
  16      * @var string
  17      */
  18      var $html;
  19  
  20      /**
  21      * The text part of the message(only used in TEXT only messages)
  22      * @var string
  23      */
  24      var $text;
  25  
  26      /**
  27      * The main body of the message after building
  28      * @var string
  29      */
  30      var $output;
  31  
  32      /**
  33      * The alternative text to the HTML part (only used in HTML messages)
  34      * @var string
  35      */
  36      var $html_text;
  37  
  38      /**
  39      * An array of embedded images/objects
  40      * @var array
  41      */
  42      var $html_images;
  43  
  44      /**
  45      * An array of recognised image types for the findHtmlImages() method
  46      * @var array
  47      */
  48      var $image_types;
  49  
  50      /**
  51      * Parameters that affect the build process
  52      * @var array
  53      */
  54      var $build_params;
  55  
  56      /**
  57      * Array of attachments
  58      * @var array
  59      */
  60      var $attachments;
  61  
  62      /**
  63      * The main message headers
  64      * @var array
  65      */
  66      var $headers;
  67  
  68      /**
  69      * Whether the message has been built or not
  70      * @var boolean
  71      */
  72      var $is_built;
  73      
  74      /**
  75      * The return path address. If not set the From:
  76      * address is used instead
  77      * @var string
  78      */
  79      var $return_path;
  80      
  81      /**
  82      * Array of information needed for smtp sending
  83      * @var array
  84      */
  85      var $smtp_params;
  86  
  87  /**
  88  * Constructor function. Sets the headers
  89  * if supplied.
  90  */
  91  
  92  	function htmlMimeMail()
  93      {
  94          /**
  95          * Initialise some variables.
  96          */
  97          $this->html_images = array();
  98          $this->headers     = array();
  99          $this->is_built    = false;
 100  
 101          /**
 102          * If you want the auto load functionality
 103          * to find other image/file types, add the
 104          * extension and content type here.
 105          */
 106          $this->image_types = array(
 107                                      'gif'    => 'image/gif',
 108                                      'jpg'    => 'image/jpeg',
 109                                      'jpeg'    => 'image/jpeg',
 110                                      'jpe'    => 'image/jpeg',
 111                                      'bmp'    => 'image/bmp',
 112                                      'png'    => 'image/png',
 113                                      'tif'    => 'image/tiff',
 114                                      'tiff'    => 'image/tiff',
 115                                      'swf'    => 'application/x-shockwave-flash'
 116                                    );
 117  
 118          /**
 119          * Set these up
 120          */
 121          $this->build_params['html_encoding'] = 'quoted-printable';
 122          $this->build_params['text_encoding'] = '7bit';
 123          $this->build_params['html_charset']  = 'ISO-8859-1';
 124          $this->build_params['text_charset']  = 'ISO-8859-1';
 125          $this->build_params['head_charset']  = 'ISO-8859-1';
 126          $this->build_params['text_wrap']     = 998;
 127  
 128          /**
 129          * Defaults for smtp sending
 130          */
 131          if (!empty($GLOBALS['HTTP_SERVER_VARS']['HTTP_HOST'])) {
 132              $helo = $GLOBALS['HTTP_SERVER_VARS']['HTTP_HOST'];
 133          } elseif (!empty($GLOBALS['HTTP_SERVER_VARS']['SERVER_NAME'])) {
 134              $helo = $GLOBALS['HTTP_SERVER_VARS']['SERVER_NAME'];
 135          } else {
 136              $helo = 'localhost';
 137          }
 138  
 139          $this->smtp_params['host'] = 'localhost';
 140          $this->smtp_params['port'] = 25;
 141          $this->smtp_params['helo'] = $helo;
 142          $this->smtp_params['auth'] = false;
 143          $this->smtp_params['user'] = '';
 144          $this->smtp_params['pass'] = '';
 145  
 146          /**
 147          * Make sure the MIME version header is first.
 148          */
 149          $this->headers['MIME-Version'] = '1.0';
 150      }
 151  
 152  /**
 153  * This function will read a file in
 154  * from a supplied filename and return
 155  * it. This can then be given as the first
 156  * argument of the the functions
 157  * add_html_image() or add_attachment().
 158  */
 159  	function getFile($filename)
 160      {
 161          $return = '';
 162          if ($fp = fopen($filename, 'rb')) {
 163              while (!feof($fp)) {
 164                  $return .= fread($fp, 1024);
 165              }
 166              fclose($fp);
 167              return $return;
 168  
 169          } else {
 170              return false;
 171          }
 172      }
 173  
 174  /**
 175  * Accessor to set the CRLF style
 176  */
 177  	function setCrlf($crlf = "\n")
 178      {
 179          if (!defined('CRLF')) {
 180              define('CRLF', $crlf, true);
 181          }
 182  
 183          if (!defined('MAIL_MIMEPART_CRLF')) {
 184              define('MAIL_MIMEPART_CRLF', $crlf, true);
 185          }
 186      }
 187  
 188  /**
 189  * Accessor to set the SMTP parameters
 190  */
 191  	function setSMTPParams($host = null, $port = null, $helo = null, $auth = null, $user = null, $pass = null)
 192      {
 193          if (!is_null($host)) $this->smtp_params['host'] = $host;
 194          if (!is_null($port)) $this->smtp_params['port'] = $port;
 195          if (!is_null($helo)) $this->smtp_params['helo'] = $helo;
 196          if (!is_null($auth)) $this->smtp_params['auth'] = $auth;
 197          if (!is_null($user)) $this->smtp_params['user'] = $user;
 198          if (!is_null($pass)) $this->smtp_params['pass'] = $pass;
 199      }
 200  
 201  /**
 202  * Accessor function to set the text encoding
 203  */
 204  	function setTextEncoding($encoding = '7bit')
 205      {
 206          $this->build_params['text_encoding'] = $encoding;
 207      }
 208  
 209  /**
 210  * Accessor function to set the HTML encoding
 211  */
 212  	function setHtmlEncoding($encoding = 'quoted-printable')
 213      {
 214          $this->build_params['html_encoding'] = $encoding;
 215      }
 216  
 217  /**
 218  * Accessor function to set the text charset
 219  */
 220  	function setTextCharset($charset = 'ISO-8859-1')
 221      {
 222          $this->build_params['text_charset'] = $charset;
 223      }
 224  
 225  /**
 226  * Accessor function to set the HTML charset
 227  */
 228  	function setHtmlCharset($charset = 'ISO-8859-1')
 229      {
 230          $this->build_params['html_charset'] = $charset;
 231      }
 232  
 233  /**
 234  * Accessor function to set the header encoding charset
 235  */
 236  	function setHeadCharset($charset = 'ISO-8859-1')
 237      {
 238          $this->build_params['head_charset'] = $charset;
 239      }
 240  
 241  /**
 242  * Accessor function to set the text wrap count
 243  */
 244  	function setTextWrap($count = 998)
 245      {
 246          $this->build_params['text_wrap'] = $count;
 247      }
 248  
 249  /**
 250  * Accessor to set a header
 251  */
 252  	function setHeader($name, $value)
 253      {
 254          $this->headers[$name] = $value;
 255      }
 256  
 257  /**
 258  * Accessor to add a Subject: header
 259  */
 260  	function setSubject($subject)
 261      {
 262          $this->headers['Subject'] = $subject;
 263      }
 264  
 265  /**
 266  * Accessor to add a From: header
 267  */
 268  	function setFrom($from)
 269      {
 270          $this->headers['From'] = $from;
 271      }
 272  
 273  /**
 274  * Accessor to set the return path
 275  */
 276  	function setReturnPath($return_path)
 277      {
 278          $this->return_path = $return_path;
 279      }
 280  
 281  /**
 282  * Accessor to add a Cc: header
 283  */
 284  	function setCc($cc)
 285      {
 286          $this->headers['Cc'] = $cc;
 287      }
 288  
 289  /**
 290  * Accessor to add a Bcc: header
 291  */
 292  	function setBcc($bcc)
 293      {
 294          $this->headers['Bcc'] = $bcc;
 295      }
 296  
 297  /**
 298  * Adds plain text. Use this function
 299  * when NOT sending html email
 300  */
 301  	function setText($text = '')
 302      {
 303          $this->text = $text;
 304      }
 305  
 306  /**
 307  * Adds a html part to the mail.
 308  * Also replaces image names with
 309  * content-id's.
 310  */
 311  	function setHtml($html, $text = null, $images_dir = null)
 312      {
 313          $this->html      = $html;
 314          $this->html_text = $text;
 315  
 316          if (isset($images_dir)) {
 317              $this->_findHtmlImages($images_dir);
 318          }
 319      }
 320  
 321  /**
 322  * Function for extracting images from
 323  * html source. This function will look
 324  * through the html code supplied by add_html()
 325  * and find any file that ends in one of the
 326  * extensions defined in $obj->image_types.
 327  * If the file exists it will read it in and
 328  * embed it, (not an attachment).
 329  *
 330  * @author Dan Allen
 331  */
 332  	function _findHtmlImages($images_dir)
 333      {
 334          // Build the list of image extensions
 335          while (list($key,) = each($this->image_types)) {
 336              $extensions[] = $key;
 337          }
 338  
 339          preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $images);
 340  
 341          for ($i=0; $i<count($images[1]); $i++) {
 342              if (file_exists($images_dir . $images[1][$i])) {
 343                  $html_images[] = $images[1][$i];
 344                  $this->html = str_replace($images[1][$i], basename($images[1][$i]), $this->html);
 345              }
 346          }
 347  
 348          if (!empty($html_images)) {
 349  
 350              // If duplicate images are embedded, they may show up as attachments, so remove them.
 351              $html_images = array_unique($html_images);
 352              sort($html_images);
 353      
 354              for ($i=0; $i<count($html_images); $i++) {
 355                  if ($image = $this->getFile($images_dir.$html_images[$i])) {
 356                      $ext = substr($html_images[$i], strrpos($html_images[$i], '.') + 1);
 357                      $content_type = $this->image_types[strtolower($ext)];
 358                      $this->addHtmlImage($image, basename($html_images[$i]), $content_type);
 359                  }
 360              }
 361          }
 362      }
 363  
 364  /**
 365  * Adds an image to the list of embedded
 366  * images.
 367  */
 368  	function addHtmlImage($file, $name = '', $c_type='application/octet-stream')
 369      {
 370          $this->html_images[] = array(
 371                                          'body'   => $file,
 372                                          'name'   => $name,
 373                                          'c_type' => $c_type,
 374                                          'cid'    => md5(uniqid(time()))
 375                                      );
 376      }
 377  
 378  
 379  /**
 380  * Adds a file to the list of attachments.
 381  */
 382  	function addAttachment($file, $name = '', $c_type='application/octet-stream', $encoding = 'base64')
 383      {
 384          $this->attachments[] = array(
 385                                      'body'        => $file,
 386                                      'name'        => $name,
 387                                      'c_type'    => $c_type,
 388                                      'encoding'    => $encoding
 389                                    );
 390      }
 391  
 392  /**
 393  * Adds a text subpart to a mime_part object
 394  */
 395      function &_addTextPart(&$obj, $text)
 396      {
 397          $params['content_type'] = 'text/plain';
 398          $params['encoding']     = $this->build_params['text_encoding'];
 399          $params['charset']      = $this->build_params['text_charset'];
 400          if (is_object($obj)) {
 401              return $obj->addSubpart($text, $params);
 402          } else {
 403              return new Mail_mimePart($text, $params);
 404          }
 405      }
 406  
 407  /**
 408  * Adds a html subpart to a mime_part object
 409  */
 410      function &_addHtmlPart(&$obj)
 411      {
 412          $params['content_type'] = 'text/html';
 413          $params['encoding']     = $this->build_params['html_encoding'];
 414          $params['charset']      = $this->build_params['html_charset'];
 415          if (is_object($obj)) {
 416              return $obj->addSubpart($this->html, $params);
 417          } else {
 418              return new Mail_mimePart($this->html, $params);
 419          }
 420      }
 421  
 422  /**
 423  * Starts a message with a mixed part
 424  */
 425      function &_addMixedPart()
 426      {
 427          $params['content_type'] = 'multipart/mixed';
 428          return new Mail_mimePart('', $params);
 429      }
 430  
 431  /**
 432  * Adds an alternative part to a mime_part object
 433  */
 434      function &_addAlternativePart(&$obj)
 435      {
 436          $params['content_type'] = 'multipart/alternative';
 437          if (is_object($obj)) {
 438              return $obj->addSubpart('', $params);
 439          } else {
 440              return new Mail_mimePart('', $params);
 441          }
 442      }
 443  
 444  /**
 445  * Adds a html subpart to a mime_part object
 446  */
 447      function &_addRelatedPart(&$obj)
 448      {
 449          $params['content_type'] = 'multipart/related';
 450          if (is_object($obj)) {
 451              return $obj->addSubpart('', $params);
 452          } else {
 453              return new Mail_mimePart('', $params);
 454          }
 455      }
 456  
 457  /**
 458  * Adds an html image subpart to a mime_part object
 459  */
 460      function &_addHtmlImagePart(&$obj, $value)
 461      {
 462          $params['content_type'] = $value['c_type'];
 463          $params['encoding']     = 'base64';
 464          $params['disposition']  = 'inline';
 465          $params['dfilename']    = $value['name'];
 466          $params['cid']          = $value['cid'];
 467          $obj->addSubpart($value['body'], $params);
 468      }
 469  
 470  /**
 471  * Adds an attachment subpart to a mime_part object
 472  */
 473      function &_addAttachmentPart(&$obj, $value)
 474      {
 475          $params['content_type'] = $value['c_type'];
 476          $params['encoding']     = $value['encoding'];
 477          $params['disposition']  = 'attachment';
 478          $params['dfilename']    = $value['name'];
 479          $obj->addSubpart($value['body'], $params);
 480      }
 481  
 482  /**
 483  * Builds the multipart message from the
 484  * list ($this->_parts). $params is an
 485  * array of parameters that shape the building
 486  * of the message. Currently supported are:
 487  *
 488  * $params['html_encoding'] - The type of encoding to use on html. Valid options are
 489  *                            "7bit", "quoted-printable" or "base64" (all without quotes).
 490  *                            7bit is EXPRESSLY NOT RECOMMENDED. Default is quoted-printable
 491  * $params['text_encoding'] - The type of encoding to use on plain text Valid options are
 492  *                            "7bit", "quoted-printable" or "base64" (all without quotes).
 493  *                            Default is 7bit
 494  * $params['text_wrap']     - The character count at which to wrap 7bit encoded data.
 495  *                            Default this is 998.
 496  * $params['html_charset']  - The character set to use for a html section.
 497  *                            Default is ISO-8859-1
 498  * $params['text_charset']  - The character set to use for a text section.
 499  *                          - Default is ISO-8859-1
 500  * $params['head_charset']  - The character set to use for header encoding should it be needed.
 501  *                          - Default is ISO-8859-1
 502  */
 503  	function buildMessage($params = array())
 504      {
 505          if (!empty($params)) {
 506              while (list($key, $value) = each($params)) {
 507                  $this->build_params[$key] = $value;
 508              }
 509          }
 510  
 511          if (!empty($this->html_images)) {
 512              foreach ($this->html_images as $value) {
 513                  $this->html = str_replace($value['name'], 'cid:'.$value['cid'], $this->html);
 514              }
 515          }
 516  
 517          $null        = null;
 518          $attachments = !empty($this->attachments) ? true : false;
 519          $html_images = !empty($this->html_images) ? true : false;
 520          $html        = !empty($this->html)        ? true : false;
 521          $text        = isset($this->text)         ? true : false;
 522  
 523          switch (true) {
 524              case $text AND !$attachments:
 525                  $message = &$this->_addTextPart($null, $this->text);
 526                  break;
 527  
 528              case !$text AND $attachments AND !$html:
 529                  $message = &$this->_addMixedPart();
 530  
 531                  for ($i=0; $i<count($this->attachments); $i++) {
 532                      $this->_addAttachmentPart($message, $this->attachments[$i]);
 533                  }
 534                  break;
 535  
 536              case $text AND $attachments:
 537                  $message = &$this->_addMixedPart();
 538                  $this->_addTextPart($message, $this->text);
 539  
 540                  for ($i=0; $i<count($this->attachments); $i++) {
 541                      $this->_addAttachmentPart($message, $this->attachments[$i]);
 542                  }
 543                  break;
 544  
 545              case $html AND !$attachments AND !$html_images:
 546                  if (!is_null($this->html_text)) {
 547                      $message = &$this->_addAlternativePart($null);
 548                      $this->_addTextPart($message, $this->html_text);
 549                      $this->_addHtmlPart($message);
 550                  } else {
 551                      $message = &$this->_addHtmlPart($null);
 552                  }
 553                  break;
 554  
 555              case $html AND !$attachments AND $html_images:
 556                  if (!is_null($this->html_text)) {
 557                      $message = &$this->_addAlternativePart($null);
 558                      $this->_addTextPart($message, $this->html_text);
 559                      $related = &$this->_addRelatedPart($message);
 560                  } else {
 561                      $message = &$this->_addRelatedPart($null);
 562                      $related = &$message;
 563                  }
 564                  $this->_addHtmlPart($related);
 565                  for ($i=0; $i<count($this->html_images); $i++) {
 566                      $this->_addHtmlImagePart($related, $this->html_images[$i]);
 567                  }
 568                  break;
 569  
 570              case $html AND $attachments AND !$html_images:
 571                  $message = &$this->_addMixedPart();
 572                  if (!is_null($this->html_text)) {
 573                      $alt = &$this->_addAlternativePart($message);
 574                      $this->_addTextPart($alt, $this->html_text);
 575                      $this->_addHtmlPart($alt);
 576                  } else {
 577                      $this->_addHtmlPart($message);
 578                  }
 579                  for ($i=0; $i<count($this->attachments); $i++) {
 580                      $this->_addAttachmentPart($message, $this->attachments[$i]);
 581                  }
 582                  break;
 583  
 584              case $html AND $attachments AND $html_images:
 585                  $message = &$this->_addMixedPart();
 586                  if (!is_null($this->html_text)) {
 587                      $alt = &$this->_addAlternativePart($message);
 588                      $this->_addTextPart($alt, $this->html_text);
 589                      $rel = &$this->_addRelatedPart($alt);
 590                  } else {
 591                      $rel = &$this->_addRelatedPart($message);
 592                  }
 593                  $this->_addHtmlPart($rel);
 594                  for ($i=0; $i<count($this->html_images); $i++) {
 595                      $this->_addHtmlImagePart($rel, $this->html_images[$i]);
 596                  }
 597                  for ($i=0; $i<count($this->attachments); $i++) {
 598                      $this->_addAttachmentPart($message, $this->attachments[$i]);
 599                  }
 600                  break;
 601  
 602          }
 603  
 604          if (isset($message)) {
 605              $output = $message->encode();
 606              $this->output   = $output['body'];
 607              $this->headers  = array_merge($this->headers, $output['headers']);
 608  
 609              // Add message ID header
 610              srand((double)microtime()*10000000);
 611              $message_id = sprintf('<%s.%s@%s>', base_convert(time(), 10, 36), base_convert(rand(), 10, 36), !empty($GLOBALS['HTTP_SERVER_VARS']['HTTP_HOST']) ? $GLOBALS['HTTP_SERVER_VARS']['HTTP_HOST'] : $GLOBALS['HTTP_SERVER_VARS']['SERVER_NAME']);
 612              $this->headers['Message-ID'] = $message_id;
 613  
 614              $this->is_built = true;
 615              return true;
 616          } else {
 617              return false;
 618          }
 619      }
 620  
 621  /**
 622  * Function to encode a header if necessary
 623  * according to RFC2047
 624  */
 625  	function _encodeHeader($input, $charset = 'ISO-8859-1')
 626      {
 627          preg_match_all('/(\w*[\x80-\xFF]+\w*)/', $input, $matches);
 628          foreach ($matches[1] as $value) {
 629              $replacement = preg_replace('/([\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
 630              $input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
 631          }
 632          
 633          return $input;
 634      }
 635  
 636  /**
 637  * Sends the mail.
 638  *
 639  * @param  array  $recipients
 640  * @param  string $type OPTIONAL
 641  * @return mixed
 642  */
 643  	function send($recipients, $type = 'mail')
 644      {
 645          if (!defined('CRLF')) {
 646              $this->setCrlf($type == 'mail' ? "\n" : "\r\n");
 647          }
 648  
 649          if (!$this->is_built) {
 650              $this->buildMessage();
 651          }
 652  
 653          switch ($type) {
 654              case 'mail':
 655                  $subject = '';
 656                  if (!empty($this->headers['Subject'])) {
 657                      $subject = $this->_encodeHeader($this->headers['Subject'], $this->build_params['head_charset']);
 658                      unset($this->headers['Subject']);
 659                  }
 660  
 661                  // Get flat representation of headers
 662                  foreach ($this->headers as $name => $value) {
 663                      $headers[] = $name . ': ' . $this->_encodeHeader($value, $this->build_params['head_charset']);
 664                  }
 665  
 666                  $to = $this->_encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
 667  
 668                  if (!empty($this->return_path)) {
 669                      $result = @mail($to, $subject, $this->output, implode(CRLF, $headers), '-f' . $this->return_path);
 670                  } else {
 671                      $result = @mail($to, $subject, $this->output, implode(CRLF, $headers));
 672                  }
 673                  
 674                  // Reset the subject in case mail is resent
 675                  if ($subject !== '') {
 676                      $this->headers['Subject'] = $subject;
 677                  }
 678                  
 679                  // Return
 680                  return $result;
 681                  break;
 682  
 683              case 'smtp':
 684                  require_once(dirname(__FILE__) . '/smtp.php');
 685                  require_once(dirname(__FILE__) . '/RFC822.php');
 686                  $smtp = &smtp::connect($this->smtp_params);
 687                  if ($smtp->status != SMTP_STATUS_CONNECTED) {
 688                      $this->errors = $smtp->errors;
 689                      return false;
 690                  }
 691  
 692                  // Parse recipients argument for internet addresses
 693                  foreach ($recipients as $recipient) {
 694                      $addresses = Mail_RFC822::parseAddressList($recipient, $this->smtp_params['helo'], null, false);
 695                      foreach ($addresses as $address) {
 696                          $smtp_recipients[] = sprintf('%s@%s', $address->mailbox, $address->host);
 697                      }
 698                  }
 699                  unset($addresses); // These are reused
 700                  unset($address);   // These are reused
 701  
 702                  // Get flat representation of headers, parsing
 703                  // Cc and Bcc as we go
 704                  foreach ($this->headers as $name => $value) {
 705                      if ($name == 'Cc' OR $name == 'Bcc') {
 706                          $addresses = Mail_RFC822::parseAddressList($value, $this->smtp_params['helo'], null, false);
 707                          foreach ($addresses as $address) {
 708                              $smtp_recipients[] = sprintf('%s@%s', $address->mailbox, $address->host);
 709                          }
 710                      }
 711                      if ($name == 'Bcc') {
 712                          continue;
 713                      }
 714                      $headers[] = $name . ': ' . $this->_encodeHeader($value, $this->build_params['head_charset']);
 715                  }
 716                  // Add To header based on $recipients argument
 717                  $headers[] = 'To: ' . $this->_encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
 718                  
 719                  // Add headers to send_params
 720                  $send_params['headers']    = $headers;
 721                  $send_params['recipients'] = array_values(array_unique($smtp_recipients));
 722                  $send_params['body']       = $this->output;
 723  
 724                  // Setup return path
 725                  if (isset($this->return_path)) {
 726                      $send_params['from'] = $this->return_path;
 727                  } elseif (!empty($this->headers['From'])) {
 728                      $from = Mail_RFC822::parseAddressList($this->headers['From']);
 729                      $send_params['from'] = sprintf('%s@%s', $from[0]->mailbox, $from[0]->host);
 730                  } else {
 731                      $send_params['from'] = 'postmaster@' . $this->smtp_params['helo'];
 732                  }
 733  
 734                  // Send it
 735                  if (!$smtp->send($send_params)) {
 736                      $this->errors = $smtp->errors;
 737                      return false;
 738                  }
 739                  return true;
 740                  break;
 741          }
 742      }
 743  
 744  /**
 745  * Use this method to return the email
 746  * in message/rfc822 format. Useful for
 747  * adding an email to another email as
 748  * an attachment. there's a commented
 749  * out example in example.php.
 750  */
 751  	function getRFC822($recipients)
 752      {
 753          // Make up the date header as according to RFC822
 754          $this->setHeader('Date', date('D, d M y H:i:s O'));
 755  
 756          if (!defined('CRLF')) {
 757              $this->setCrlf($type == 'mail' ? "\n" : "\r\n");
 758          }
 759  
 760          if (!$this->is_built) {
 761              $this->buildMessage();
 762          }
 763  
 764          // Return path ?
 765          if (isset($this->return_path)) {
 766              $headers[] = 'Return-Path: ' . $this->return_path;
 767          }
 768  
 769          // Get flat representation of headers
 770          foreach ($this->headers as $name => $value) {
 771              $headers[] = $name . ': ' . $value;
 772          }
 773          $headers[] = 'To: ' . implode(', ', $recipients);
 774  
 775          return implode(CRLF, $headers) . CRLF . CRLF . $this->output;
 776      }
 777  } // End of class.
 778  ?>

title

Description

title

Description

title

Description

title

title

Body