[ PHPXref.com ] [ Generated: Thu Aug 19 03:35:06 2010 ] [ FluxBB 1.4.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/include/ -> email.php (source)

   1  <?php
   2  
   3  /**
   4   * Copyright (C) 2008-2010 FluxBB
   5   * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
   6   * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
   7   */
   8  
   9  // Make sure no one attempts to run this script "directly"
  10  if (!defined('PUN'))
  11      exit;
  12  
  13  
  14  //
  15  // Validate an email address
  16  //
  17  function is_valid_email($email)
  18  {
  19      if (strlen($email) > 80)
  20          return false;
  21  
  22      return preg_match('/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|("[^"]+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-zA-Z\d\-]+\.)+[a-zA-Z]{2,}))$/', $email);
  23  }
  24  
  25  
  26  //
  27  // Check if $email is banned
  28  //
  29  function is_banned_email($email)
  30  {
  31      global $pun_bans;
  32  
  33      foreach ($pun_bans as $cur_ban)
  34      {
  35          if ($cur_ban['email'] != '' &&
  36              ($email == $cur_ban['email'] ||
  37              (strpos($cur_ban['email'], '@') === false && stristr($email, '@'.$cur_ban['email']))))
  38              return true;
  39      }
  40  
  41      return false;
  42  }
  43  
  44  
  45  //
  46  // Wrapper for PHP's mail()
  47  //
  48  function pun_mail($to, $subject, $message, $reply_to_email = '', $reply_to_name = '')
  49  {
  50      global $pun_config, $lang_common;
  51  
  52      // Default sender/return address
  53      $from_name = str_replace('"', '', $pun_config['o_board_title'].' '.$lang_common['Mailer']);
  54      $from_email = $pun_config['o_webmaster_email'];
  55  
  56      // Do a little spring cleaning
  57      $to = pun_trim(preg_replace('#[\n\r]+#s', '', $to));
  58      $subject = pun_trim(preg_replace('#[\n\r]+#s', '', $subject));
  59      $from_email = pun_trim(preg_replace('#[\n\r:]+#s', '', $from_email));
  60      $from_name = pun_trim(preg_replace('#[\n\r:]+#s', '', str_replace('"', '', $from_name)));
  61      $reply_to_email = pun_trim(preg_replace('#[\n\r:]+#s', '', $reply_to_email));
  62      $reply_to_name = pun_trim(preg_replace('#[\n\r:]+#s', '', str_replace('"', '', $reply_to_name)));
  63  
  64      // Set up some headers to take advantage of UTF-8
  65      $from = "=?UTF-8?B?".base64_encode($from_name)."?=".' <'.$from_email.'>';
  66      $subject = "=?UTF-8?B?".base64_encode($subject)."?=";
  67  
  68      $headers = 'From: '.$from."\r\n".'Date: '.gmdate('r')."\r\n".'MIME-Version: 1.0'."\r\n".'Content-transfer-encoding: 8bit'."\r\n".'Content-type: text/plain; charset=utf-8'."\r\n".'X-Mailer: FluxBB Mailer';
  69  
  70      // If we specified a reply-to email, we deal with it here
  71      if (!empty($reply_to_email))
  72      {
  73          $reply_to = "=?UTF-8?B?".base64_encode($reply_to_name)."?=".' <'.$reply_to_email.'>';
  74  
  75          $headers .= "\r\n".'Reply-To: '.$reply_to;
  76      }
  77  
  78      // Make sure all linebreaks are CRLF in message (and strip out any NULL bytes)
  79      $message = str_replace(array("\n", "\0"), array("\r\n", ''), pun_linebreaks($message));
  80  
  81      if ($pun_config['o_smtp_host'] != '')
  82          smtp_mail($to, $subject, $message, $headers);
  83      else
  84      {
  85          // Change the linebreaks used in the headers according to OS
  86          if (strtoupper(substr(PHP_OS, 0, 3)) == 'MAC')
  87              $headers = str_replace("\r\n", "\r", $headers);
  88          else if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN')
  89              $headers = str_replace("\r\n", "\n", $headers);
  90  
  91          mail($to, $subject, $message, $headers);
  92      }
  93  }
  94  
  95  
  96  //
  97  // This function was originally a part of the phpBB Group forum software phpBB2 (http://www.phpbb.com)
  98  // They deserve all the credit for writing it. I made small modifications for it to suit PunBB and it's coding standards
  99  //
 100  function server_parse($socket, $expected_response)
 101  {
 102      $server_response = '';
 103      while (substr($server_response, 3, 1) != ' ')
 104      {
 105          if (!($server_response = fgets($socket, 256)))
 106              error('Couldn\'t get mail server response codes. Please contact the forum administrator.', __FILE__, __LINE__);
 107      }
 108  
 109      if (!(substr($server_response, 0, 3) == $expected_response))
 110          error('Unable to send email. Please contact the forum administrator with the following error message reported by the SMTP server: "'.$server_response.'"', __FILE__, __LINE__);
 111  }
 112  
 113  
 114  //
 115  // This function was originally a part of the phpBB Group forum software phpBB2 (http://www.phpbb.com)
 116  // They deserve all the credit for writing it. I made small modifications for it to suit PunBB and it's coding standards.
 117  //
 118  function smtp_mail($to, $subject, $message, $headers = '')
 119  {
 120      global $pun_config;
 121  
 122      $recipients = explode(',', $to);
 123  
 124      // Sanitize the message
 125      $message = str_replace("\r\n.", "\r\n..", $message);
 126      $message = (substr($message, 0, 1) == '.' ? '.'.$message : $message);
 127  
 128      // Are we using port 25 or a custom port?
 129      if (strpos($pun_config['o_smtp_host'], ':') !== false)
 130          list($smtp_host, $smtp_port) = explode(':', $pun_config['o_smtp_host']);
 131      else
 132      {
 133          $smtp_host = $pun_config['o_smtp_host'];
 134          $smtp_port = 25;
 135      }
 136  
 137      if ($pun_config['o_smtp_ssl'] == '1')
 138          $smtp_host = 'ssl://'.$smtp_host;
 139  
 140      if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15)))
 141          error('Could not connect to smtp host "'.$pun_config['o_smtp_host'].'" ('.$errno.') ('.$errstr.')', __FILE__, __LINE__);
 142  
 143      server_parse($socket, '220');
 144  
 145      if ($pun_config['o_smtp_user'] != '' && $pun_config['o_smtp_pass'] != '')
 146      {
 147          fwrite($socket, 'EHLO '.$smtp_host."\r\n");
 148          server_parse($socket, '250');
 149  
 150          fwrite($socket, 'AUTH LOGIN'."\r\n");
 151          server_parse($socket, '334');
 152  
 153          fwrite($socket, base64_encode($pun_config['o_smtp_user'])."\r\n");
 154          server_parse($socket, '334');
 155  
 156          fwrite($socket, base64_encode($pun_config['o_smtp_pass'])."\r\n");
 157          server_parse($socket, '235');
 158      }
 159      else
 160      {
 161          fwrite($socket, 'HELO '.$smtp_host."\r\n");
 162          server_parse($socket, '250');
 163      }
 164  
 165      fwrite($socket, 'MAIL FROM: <'.$pun_config['o_webmaster_email'].'>'."\r\n");
 166      server_parse($socket, '250');
 167  
 168      foreach ($recipients as $email)
 169      {
 170          fwrite($socket, 'RCPT TO: <'.$email.'>'."\r\n");
 171          server_parse($socket, '250');
 172      }
 173  
 174      fwrite($socket, 'DATA'."\r\n");
 175      server_parse($socket, '354');
 176  
 177      fwrite($socket, 'Subject: '.$subject."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n");
 178  
 179      fwrite($socket, '.'."\r\n");
 180      server_parse($socket, '250');
 181  
 182      fwrite($socket, 'QUIT'."\r\n");
 183      fclose($socket);
 184  
 185      return true;
 186  }


[ Powered by PHPXref - Served by Debian GNU/Linux ]