[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_handlers/ -> smtp.php (source)

   1  <?php
   2  if (!defined('e107_INIT')) { exit; }
   3  
   4  /***************************************************************************
   5  *                              smtp.php
   6  *                       -------------------
   7  *   begin                : Wed May 09 2001
   8  *   copyright            : (C) 2001 The phpBB Group
   9  *   email                : support@phpbb.com
  10  *
  11  *   $Id: smtp.php,v 1.4 2005/12/14 17:37:34 sweetas Exp $
  12  *
  13  ***************************************************************************/
  14      
  15  /***************************************************************************
  16  *
  17  *   This program is free software; you can redistribute it and/or modify
  18  *   it under the terms of the GNU General Public License as published by
  19  *   the Free Software Foundation; either version 2 of the License, or
  20  *   (at your option) any later version.
  21  *
  22  ***************************************************************************/
  23      
  24  /***************************************************************************
  25  *
  26  *   modified for use with e107 website system
  27  *   http://e107.org
  28  *
  29  ***************************************************************************/
  30      
  31  //
  32  // This function has been modified as provided
  33  // by SirSir to allow multiline responses when
  34  // using SMTP Extensions
  35  //
  36  function server_parse($socket, $response) {
  37      while (substr($server_response, 3, 1) != ' ' ) {
  38          if (!($server_response = fgets($socket, 256) ) ) {
  39              print("Couldn't get mail server response codes". __LINE__."&nbsp;".__FILE__);
  40              return FALSE;
  41          }
  42      }
  43       
  44      if (!(substr($server_response, 0, 3) == $response ) ) {
  45          // echo ("Ran into problems sending Mail. Response: $server_response ");
  46          return FALSE;
  47      }
  48  }
  49      
  50  /****************************************************************************
  51  * Function:   smtpmail
  52  * Description:  This is a functional replacement for php's builtin mail
  53  *      function, that uses smtp.
  54  * Usage:   The usage for this function is identical to that of php's
  55  *      built in mail function.
  56  ****************************************************************************/
  57  function smtpmail($mail_to, $subject, $message, $headers = "") {
  58      // For now I'm using an array based $smtp_vars to hold the smtp server
  59      // info, but it should probably change to $board_config...
  60      // then the relevant info would be $board_config['smtp_host'] and
  61      // $board_config['smtp_port'].
  62      global $pref, $e107;
  63      //
  64      // Fix any bare linefeeds in the message to make it RFC821 Compliant.
  65      //
  66      $message = preg_replace("/(?<!\r)\n/si", "\r\n", $message);
  67       
  68      if ($headers != "") {
  69          if (is_array($headers)) {
  70              if (sizeof($headers) > 1) {
  71                  $headers = join("\r\n", $headers);
  72              } else {
  73                  $headers = $headers[0];
  74              }
  75          }
  76          $headers = chop($headers);
  77           
  78          //
  79          // Make sure there are no bare linefeeds in the headers
  80          //
  81          $headers = preg_replace("/(?<!\r)\n/si", "\r\n", $headers);
  82          //
  83          // Ok this is rather confusing all things considered,
  84          // but we have to grab bcc and cc headers and treat them differently
  85          // Something we really didn't take into consideration originally
  86          //
  87          $header_array = explode("\r\n", $headers);
  88          @reset($header_array);
  89          $headers = "";
  90          while (list(, $header) = each($header_array) ) {
  91              if (preg_match("/^cc:/si", $header) ) {
  92                  $cc = preg_replace("/^cc:(.*)/si", "\\1", $header);
  93              }
  94              else if(preg_match("/^bcc:/si", $header )) {
  95                  $bcc = preg_replace("/^bcc:(.*)/si", "\\1", $header);
  96                  $header = "";
  97              }
  98              $headers .= $header . "\r\n";
  99          }
 100          $headers = chop($headers);
 101          $cc = explode(",", $cc);
 102          $bcc = explode(",", $bcc);
 103      }
 104       
 105      $mail_to_array = explode(",", $mail_to);
 106       
 107      //
 108      // Ok we have error checked as much as we can to this point let's get on
 109      // it already.
 110      //
 111      if (!$socket = fsockopen($pref['smtp_server'], 25, $errno, $errstr, 20) ) {
 112          print ("Could not connect to smtp host. <br />$errno: $errstr");
 113          return FALSE;
 114      }
 115      server_parse($socket, "220");
 116      $myIP = gethostbyname ($_SERVER['SERVER_NAME']);
 117      $myServer = $e107->get_host_name($myIP);
 118       
 119      if (!empty($pref['smtp_username']) && !empty($pref['smtp_password']) ) {
 120          // Send the RFC2554 specified EHLO.
 121          // This improved as provided by SirSir to accomodate
 122          // both SMTP AND ESMTP capable servers
 123          fputs($socket, "EHLO " . $myServer . "\r\n");
 124          server_parse($socket, "250");
 125           
 126          fputs($socket, "AUTH LOGIN\r\n");
 127          server_parse($socket, "334");
 128          fputs($socket, base64_encode($pref['smtp_username']) . "\r\n");
 129          server_parse($socket, "334");
 130          fputs($socket, base64_encode($pref['smtp_password']) . "\r\n");
 131          server_parse($socket, "235");
 132      } else {
 133          // Send the RFC821 specified HELO.
 134          fputs($socket, "HELO " . $myServer . "\r\n");
 135          server_parse($socket, "250");
 136      }
 137       
 138      // From this point onward most server response codes should be 250
 139      // Specify who the mail is from....
 140      fputs($socket, "MAIL FROM: <" . $pref['siteadminemail'] . ">\r\n");
 141      server_parse($socket, "250");
 142       
 143      // Specify each user to send to and build to header.
 144      $to_header = "To: ";
 145      @reset($mail_to_array );
 146      while (list(, $mail_to_address ) = each($mail_to_array )) {
 147          //
 148          // Add an additional bit of error checking to the To field.
 149          //
 150          $mail_to_address = trim($mail_to_address);
 151          if (preg_match('/[^ ]+\@[^ ]+/', $mail_to_address) ) {
 152              fputs($socket, "RCPT TO: <$mail_to_address>\r\n" );
 153              server_parse($socket, "250" );
 154          }
 155          $to_header .= "<$mail_to_address>";
 156      }
 157      // Ok now do the CC and BCC fields...
 158      @reset($bcc );
 159      while (list(, $bcc_address ) = each($bcc )) {
 160          //
 161          // Add an additional bit of error checking to bcc header...
 162          //
 163          $bcc_address = trim($bcc_address );
 164          if (preg_match('/[^ ]+\@[^ ]+/', $bcc_address) ) {
 165              fputs($socket, "RCPT TO: <$bcc_address>\r\n" );
 166              server_parse($socket, "250" );
 167          }
 168      }
 169      @reset($cc );
 170      while (list(, $cc_address ) = each($cc )) {
 171          //
 172          // Add an additional bit of error checking to cc header
 173          //
 174          $cc_address = trim($cc_address );
 175          if (preg_match('/[^ ]+\@[^ ]+/', $cc_address) ) {
 176              fputs($socket, "RCPT TO: <$cc_address>\r\n");
 177              server_parse($socket, "250");
 178          }
 179      }
 180      // Ok now we tell the server we are ready to start sending data
 181      fputs($socket, "DATA\r\n");
 182       
 183      // This is the last response code we look for until the end of the message.
 184      server_parse($socket, "354");
 185       
 186      // Send the Subject Line...
 187      fputs($socket, "Subject: $subject\r\n");
 188       
 189      // Now the To Header.
 190      fputs($socket, "$to_header\r\n");
 191       
 192      // Now any custom headers....
 193      fputs($socket, "$headers\r\n\r\n");
 194       
 195      // Ok now we are ready for the message...
 196      fputs($socket, "$message\r\n");
 197       
 198      // Ok the all the ingredients are mixed in let's cook this puppy...
 199      fputs($socket, ".\r\n");
 200      server_parse($socket, "250");
 201       
 202      // Now tell the server we are done and close the socket...
 203      fputs($socket, "QUIT\r\n");
 204      fclose($socket);
 205       
 206      return TRUE;
 207       
 208  }
 209      
 210  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7