[ Index ]
 

Code source de PHP NUKE 7.9

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

title

Body

[fermer]

/includes/ -> smtp.php (source)

   1  <?php
   2  /***************************************************************************

   3   *                              smtp.php

   4   *                       -------------------

   5   *   begin                : Wed May 09 2001

   6   *   copyright            : (C) 2001 The phpBB Group

   7   *   email                : support@phpbb.com

   8   *

   9   *   Id: smtp.php,v 1.16.2.10 2005/05/06 20:50:11 acydburn Exp

  10   *

  11   ***************************************************************************/
  12  
  13  /***************************************************************************

  14   *

  15   *   This program is free software; you can redistribute it and/or modify

  16   *   it under the terms of the GNU General Public License as published by

  17   *   the Free Software Foundation; either version 2 of the License, or

  18   *   (at your option) any later version.

  19   *

  20   ***************************************************************************/
  21  
  22  define('SMTP_INCLUDED', 1);
  23  
  24  //

  25  // This function has been modified as provided

  26  // by SirSir to allow multiline responses when

  27  // using SMTP Extensions

  28  //

  29  function server_parse($socket, $response, $line = __LINE__)
  30  {
  31          while (substr($server_response, 3, 1) != ' ')
  32          {
  33                  if (!($server_response = fgets($socket, 256)))
  34                  {
  35                          message_die(GENERAL_ERROR, "Couldn't get mail server response codes", "", $line, __FILE__);
  36                  }
  37          }
  38  
  39          if (!(substr($server_response, 0, 3) == $response))
  40          {
  41                  message_die(GENERAL_ERROR, "Ran into problems sending Mail. Response: $server_response", "", $line, __FILE__);
  42          }
  43  }
  44  
  45  // Replacement or substitute for PHP's mail command

  46  function smtpmail($mail_to, $subject, $message, $headers = '')
  47  {
  48          global $board_config;
  49  
  50          // Fix any bare linefeeds in the message to make it RFC821 Compliant.

  51          $message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
  52  
  53          if ($headers != '')
  54          {
  55                  if (is_array($headers))
  56                  {
  57                          if (sizeof($headers) > 1)
  58                          {
  59                                  $headers = join("\n", $headers);
  60                          }
  61                          else
  62                          {
  63                                  $headers = $headers[0];
  64                          }
  65                  }
  66                  $headers = chop($headers);
  67  
  68                  // Make sure there are no bare linefeeds in the headers

  69                  $headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);
  70  
  71                  // Ok this is rather confusing all things considered,

  72                  // but we have to grab bcc and cc headers and treat them differently

  73                  // Something we really didn't take into consideration originally

  74                  $header_array = explode("\r\n", $headers);
  75                  @reset($header_array);
  76  
  77                  $headers = '';
  78                  while(list(, $header) = each($header_array))
  79                  {
  80                          if (preg_match('#^cc:#si', $header))
  81                          {
  82                                  $cc = preg_replace('#^cc:(.*)#si', '\1', $header);
  83                          }
  84                          else if (preg_match('#^bcc:#si', $header))
  85                          {
  86                                  $bcc = preg_replace('#^bcc:(.*)#si', '\1', $header);
  87                                  $header = '';
  88                          }
  89                          $headers .= ($header != '') ? $header . "\r\n" : '';
  90                  }
  91  
  92                  $headers = chop($headers);
  93          $cc = explode(', ', $cc);
  94          $bcc = explode(', ', $bcc);
  95          }
  96  
  97          if (trim($subject) == '')
  98          {
  99                  message_die(GENERAL_ERROR, "No email Subject specified", "", __LINE__, __FILE__);
 100          }
 101  
 102          if (trim($message) == '')
 103          {
 104                  message_die(GENERAL_ERROR, "Email message was blank", "", __LINE__, __FILE__);
 105          }
 106  
 107  
 108          // Ok we have error checked as much as we can to this point let's get on

 109          // it already.

 110          if( !$socket = @fsockopen($board_config['smtp_host'], 25, $errno, $errstr, 20) )
 111          {
 112                  message_die(GENERAL_ERROR, "Could not connect to smtp host : $errno : $errstr", "", __LINE__, __FILE__);
 113          }
 114  
 115          // Wait for reply

 116          server_parse($socket, "220", __LINE__);
 117  
 118          // Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO

 119          // This improved as provided by SirSir to accomodate

 120          if( !empty($board_config['smtp_username']) && !empty($board_config['smtp_password']) )
 121          {
 122                  fputs($socket, "EHLO " . $board_config['smtp_host'] . "\r\n");
 123                  server_parse($socket, "250", __LINE__);
 124  
 125                  fputs($socket, "AUTH LOGIN\r\n");
 126                  server_parse($socket, "334", __LINE__);
 127  
 128                  fputs($socket, base64_encode($board_config['smtp_username']) . "\r\n");
 129                  server_parse($socket, "334", __LINE__);
 130  
 131                  fputs($socket, base64_encode($board_config['smtp_password']) . "\r\n");
 132                  server_parse($socket, "235", __LINE__);
 133          }
 134          else
 135          {
 136                  fputs($socket, "HELO " . $board_config['smtp_host'] . "\r\n");
 137                  server_parse($socket, "250", __LINE__);
 138          }
 139  
 140          // From this point onward most server response codes should be 250

 141          // Specify who the mail is from....

 142          fputs($socket, "MAIL FROM: <" . $board_config['board_email'] . ">\r\n");
 143          server_parse($socket, "250", __LINE__);
 144  
 145          // Specify each user to send to and build to header.

 146      $to_header = '';
 147  
 148      // Add an additional bit of error checking to the To field.

 149      $mail_to = (trim($mail_to) == '') ? 'Undisclosed-recipients:;' : trim($mail_to);
 150      if (preg_match('#[^ ]+\@[^ ]+#', $mail_to))
 151      {
 152          fputs($socket, "RCPT TO: <$mail_to>\r\n");
 153          server_parse($socket, "250", __LINE__);
 154      }
 155  
 156          // Ok now do the CC and BCC fields...

 157          @reset($bcc);
 158          while(list(, $bcc_address) = each($bcc))
 159          {
 160                  // Add an additional bit of error checking to bcc header...

 161                  $bcc_address = trim($bcc_address);
 162                  if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address))
 163                  {
 164                          fputs($socket, "RCPT TO: <$bcc_address>\r\n");
 165                          server_parse($socket, "250", __LINE__);
 166                  }
 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                  $cc_address = trim($cc_address);
 174                  if (preg_match('#[^ ]+\@[^ ]+#', $cc_address))
 175                  {
 176                          fputs($socket, "RCPT TO: <$cc_address>\r\n");
 177                          server_parse($socket, "250", __LINE__);
 178                  }
 179          }
 180  
 181          // Ok now we tell the server we are ready to start sending data

 182          fputs($socket, "DATA\r\n");
 183  
 184          // This is the last response code we look for until the end of the message.

 185          server_parse($socket, "354", __LINE__);
 186  
 187          // Send the Subject Line...

 188          fputs($socket, "Subject: $subject\r\n");
 189  
 190          // Now the To Header.

 191          fputs($socket, "To: $mail_to\r\n");
 192  
 193          // Now any custom headers....

 194          fputs($socket, "$headers\r\n\r\n");
 195  
 196          // Ok now we are ready for the message...

 197          fputs($socket, "$message\r\n");
 198  
 199          // Ok the all the ingredients are mixed in let's cook this puppy...

 200          fputs($socket, ".\r\n");
 201          server_parse($socket, "250", __LINE__);
 202  
 203          // Now tell the server we are done and close the socket...

 204          fputs($socket, "QUIT\r\n");
 205          fclose($socket);
 206  
 207          return TRUE;
 208  }
 209  
 210  ?>


Généré le : Sun Apr 1 11:11:59 2007 par Balluche grâce à PHPXref 0.7