Need to change the php configuration file to send auto email

  • jefferycxl
  • Born
  • Born
  • jefferycxl
  • Posts: 3

Post 3+ Months Ago

Hey
I am currently testing a free php forum pogram on my own pc. I used wampserver package. After I intalled the server, I move all the php files into the www folder. I can initilise the forum and I can setup the admin user. But I can not registered as the forum member, since whenever I try to register as a new member, system will try to send the new member a email. And error happen at this stage. According to error, I need to change one the php initial setting. To allow program send email.

I donot know which setting I need to change and how can I change.

Can any genius help me out.

Here are the code for the function send email.


PHP Code: [ Select ]
 
<?php
 
 
 
 <img src="./images/smilies/icon_cry.gif" alt=":cry:" title="Crying or Very sad" />
 
class emailer
 
{
 
   var $msg, $subject, $extra_headers;
 
   var $addresses, $reply_to, $from;
 
   var $use_smtp;
 
 
 
   var $tpl_msg = array();
 
 
 
   function emailer($use_smtp)
 
   {
 
      $this->reset();
 
      $this->use_smtp = $use_smtp;
 
      $this->reply_to = $this->from = '';
 
   }
 
 
 
   // Resets all the data (address, template file, etc etc to default
 
   function reset()
 
   {
 
      $this->addresses = array();
 
      $this->vars = $this->msg = $this->extra_headers = '';
 
   }
 
 
 
   // Sets an email address to send to
 
   function email_address($address)
 
   {
 
      $this->addresses['to'] = trim($address);
 
   }
 
 
 
   function cc($address)
 
   {
 
      $this->addresses['cc'][] = trim($address);
 
   }
 
 
 
   function bcc($address)
 
   {
 
      $this->addresses['bcc'][] = trim($address);
 
   }
 
 
 
   function replyto($address)
 
   {
 
      $this->reply_to = trim($address);
 
   }
 
 
 
   function from($address)
 
   {
 
      $this->from = trim($address);
 
   }
 
 
 
   // set up subject for mail
 
   function set_subject($subject = '')
 
   {
 
      $this->subject = trim(preg_replace('#[\n\r]+#s', '', $subject));
 
   }
 
 
 
   // set up extra mail headers
 
   function extra_headers($headers)
 
   {
 
      $this->extra_headers .= trim($headers) . "\n";
 
   }
 
 
 
   function use_template($template_file, $template_lang = '')
 
   {
 
      global $board_config, $phpbb_root_path;
 
 
 
      if (trim($template_file) == '')
 
      {
 
         message_die(GENERAL_ERROR, 'No template file set', '', __LINE__, __FILE__);
 
      }
 
 
 
      if (trim($template_lang) == '')
 
      {
 
         $template_lang = $board_config['default_lang'];
 
      }
 
 
 
      if (empty($this->tpl_msg[$template_lang . $template_file]))
 
      {
 
         $tpl_file = $phpbb_root_path . 'language/lang_' . $template_lang . '/email/' . $template_file . '.tpl';
 
 
 
         if (!@file_exists(@phpbb_realpath($tpl_file)))
 
         {
 
            $tpl_file = $phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/email/' . $template_file . '.tpl';
 
 
 
            if (!@file_exists(@phpbb_realpath($tpl_file)))
 
            {
 
               message_die(GENERAL_ERROR, 'Could not find email template file :: ' . $template_file, '', __LINE__, __FILE__);
 
            }
 
         }
 
 
 
         if (!($fd = @fopen($tpl_file, 'r')))
 
         {
 
            message_die(GENERAL_ERROR, 'Failed opening template file :: ' . $tpl_file, '', __LINE__, __FILE__);
 
         }
 
 
 
         $this->tpl_msg[$template_lang . $template_file] = fread($fd, filesize($tpl_file));
 
         fclose($fd);
 
      }
 
 
 
      $this->msg = $this->tpl_msg[$template_lang . $template_file];
 
 
 
      return true;
 
   }
 
 
 
   // assign variables
 
   function assign_vars($vars)
 
   {
 
      $this->vars = (empty($this->vars)) ? $vars : $this->vars . $vars;
 
   }
 
 
 
   // Send the mail out to the recipients set previously in var $this->address
 
   function send()
 
   {
 
      global $board_config, $lang, $phpEx, $phpbb_root_path, $db;
 
 
 
      // Escape all quotes, else the eval will fail.
 
      $this->msg = str_replace ("'", "\'", $this->msg);
 
      $this->msg = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "' . $\\1 . '", $this->msg);
 
 
 
      // Set vars
 
      reset ($this->vars);
 
      while (list($key, $val) = each($this->vars))
 
      {
 
         $$key = $val;
 
      }
 
 
 
      eval("\$this->msg = '$this->msg';");
 
 
 
      // Clear vars
 
      reset ($this->vars);
 
      while (list($key, $val) = each($this->vars))
 
      {
 
         unset($$key);
 
      }
 
 
 
      // We now try and pull a subject from the email body ... if it exists,
 
      // do this here because the subject may contain a variable
 
      $drop_header = '';
 
      $match = array();
 
      if (preg_match('#^(Subject:(.*?))$#m', $this->msg, $match))
 
      {
 
         $this->subject = (trim($match[2]) != '') ? trim($match[2]) : (($this->subject != '') ? $this->subject : 'No Subject');
 
         $drop_header .= '[\r\n]*?' . phpbb_preg_quote($match[1], '#');
 
      }
 
      else
 
      {
 
         $this->subject = (($this->subject != '') ? $this->subject : 'No Subject');
 
      }
 
 
 
      if (preg_match('#^(Charset:(.*?))$#m', $this->msg, $match))
 
      {
 
         $this->encoding = (trim($match[2]) != '') ? trim($match[2]) : trim($lang['ENCODING']);
 
         $drop_header .= '[\r\n]*?' . phpbb_preg_quote($match[1], '#');
 
      }
 
      else
 
      {
 
         $this->encoding = trim($lang['ENCODING']);
 
      }
 
 
 
      if ($drop_header != '')
 
      {
 
         $this->msg = trim(preg_replace('#' . $drop_header . '#s', '', $this->msg));
 
      }
 
 
 
      $to = $this->addresses['to'];
 
 
 
      $cc = (count($this->addresses['cc'])) ? implode(', ', $this->addresses['cc']) : '';
 
      $bcc = (count($this->addresses['bcc'])) ? implode(', ', $this->addresses['bcc']) : '';
 
 
 
      // Build header
 
      $this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\nMessage-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\nX-MimeOLE: Produced By phpBB2\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '')  . (($bcc != '') ? "Bcc: $bcc\n" : '');
 
 
 
      // Send message ... removed $this->encode() from subject for time being
 
      if ( $this->use_smtp )
 
      {
 
         if ( !defined('SMTP_INCLUDED') )
 
         {
 
            include($phpbb_root_path . 'includes/smtp.' . $phpEx);
 
         }
 
 
 
         $result = smtpmail($to, $this->subject, $this->msg, $this->extra_headers);
 
      }
 
      else
 
      {
 
         $empty_to_header = ($to == '') ? TRUE : FALSE;
 
         $to = ($to == '') ? (($board_config['sendmail_fix']) ? ' ' : 'Undisclosed-recipients:;') : $to;
 
   
 
         $result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
 
         
 
         if (!$result && !$board_config['sendmail_fix'] && $empty_to_header)
 
         {
 
            $to = ' ';
 
 
 
            $sql = "UPDATE " . CONFIG_TABLE . "
 
               SET config_value = '1'
 
               WHERE config_name = 'sendmail_fix'";
 
            if (!$db->sql_query($sql))
 
            {
 
               message_die(GENERAL_ERROR, 'Unable to update config table', '', __LINE__, __FILE__, $sql);
 
            }
 
 
 
            $board_config['sendmail_fix'] = 1;
 
            $result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
 
         }
 
      }
 
 
 
      // Did it work?
 
      if (!$result)
 
      {
 
         message_die(GENERAL_ERROR, 'Failed sending email :: ' . (($this->use_smtp) ? 'SMTP' : 'PHP') . ' :: ' . $result, '', __LINE__, __FILE__);
 
      }
 
 
 
      return true;
 
   }
 
 
 
   // Encodes the given string for proper display for this encoding ... nabbed
 
   // from php.net and modified. There is an alternative encoding method which
 
   // may produce lesd output but it's questionable as to its worth in this
 
   // scenario IMO
 
   function encode($str)
 
   {
 
      if ($this->encoding == '')
 
      {
 
         return $str;
 
      }
 
 
 
      // define start delimimter, end delimiter and spacer
 
      $end = "?=";
 
      $start = "=?$this->encoding?B?";
 
      $spacer = "$end\r\n $start";
 
 
 
      // determine length of encoded text within chunks and ensure length is even
 
      $length = 75 - strlen($start) - strlen($end);
 
      $length = floor($length / 2) * 2;
 
 
 
      // encode the string and split it into chunks with spacers after each chunk
 
      $str = chunk_split(base64_encode($str), $length, $spacer);
 
 
 
      // remove trailing spacer and add start and end delimiters
 
      $str = preg_replace('#' . phpbb_preg_quote($spacer, '#') . '$#', '', $str);
 
 
 
      return $start . $str . $end;
 
   }
 
 
 
   //
 
   // Attach files via MIME.
 
   //
 
   function attachFile($filename, $mimetype = "application/octet-stream", $szFromAddress, $szFilenameToDisplay)
 
   {
 
      global $lang;
 
      $mime_boundary = "--==================_846811060==_";
 
 
 
      $this->msg = '--' . $mime_boundary . "\nContent-Type: text/plain;\n\tcharset=\"" . $lang['ENCODING'] . "\"\n\n" . $this->msg;
 
 
 
      if ($mime_filename)
 
      {
 
         $filename = $mime_filename;
 
         $encoded = $this->encode_file($filename);
 
      }
 
 
 
      $fd = fopen($filename, "r");
 
      $contents = fread($fd, filesize($filename));
 
 
 
      $this->mimeOut = "--" . $mime_boundary . "\n";
 
      $this->mimeOut .= "Content-Type: " . $mimetype . ";\n\tname=\"$szFilenameToDisplay\"\n";
 
      $this->mimeOut .= "Content-Transfer-Encoding: quoted-printable\n";
 
      $this->mimeOut .= "Content-Disposition: attachment;\n\tfilename=\"$szFilenameToDisplay\"\n\n";
 
 
 
      if ( $mimetype == "message/rfc822" )
 
      {
 
         $this->mimeOut .= "From: ".$szFromAddress."\n";
 
         $this->mimeOut .= "To: ".$this->emailAddress."\n";
 
         $this->mimeOut .= "Date: ".date("D, d M Y H:i:s") . " UT\n";
 
         $this->mimeOut .= "Reply-To:".$szFromAddress."\n";
 
         $this->mimeOut .= "Subject: ".$this->mailSubject."\n";
 
         $this->mimeOut .= "X-Mailer: PHP/".phpversion()."\n";
 
         $this->mimeOut .= "MIME-Version: 1.0\n";
 
      }
 
 
 
      $this->mimeOut .= $contents."\n";
 
      $this->mimeOut .= "--" . $mime_boundary . "--" . "\n";
 
 
 
      return $out;
 
      // added -- to notify email client attachment is done
 
   }
 
 
 
   function getMimeHeaders($filename, $mime_filename="")
 
   {
 
      $mime_boundary = "--==================_846811060==_";
 
 
 
      if ($mime_filename)
 
      {
 
         $filename = $mime_filename;
 
      }
 
 
 
      $out = "MIME-Version: 1.0\n";
 
      $out .= "Content-Type: multipart/mixed;\n\tboundary=\"$mime_boundary\"\n\n";
 
      $out .= "This message is in MIME format. Since your mail reader does not understand\n";
 
      $out .= "this format, some or all of this message may not be legible.";
 
 
 
      return $out;
 
   }
 
 
 
   //
 
   // Split string by RFC 2045 semantics (76 chars per line, end with \r\n).
 
   //
 
   function myChunkSplit($str)
 
   {
 
      $stmp = $str;
 
      $len = strlen($stmp);
 
      $out = "";
 
 
 
      while ($len > 0)
 
      {
 
         if ($len >= 76)
 
         {
 
            $out .= substr($stmp, 0, 76) . "\r\n";
 
            $stmp = substr($stmp, 76);
 
            $len = $len - 76;
 
         }
 
         else
 
         {
 
            $out .= $stmp . "\r\n";
 
            $stmp = "";
 
            $len = 0;
 
         }
 
      }
 
      return $out;
 
   }
 
 
 
   //
 
   // Split the specified file up into a string and return it
 
   //
 
   function encode_file($sourcefile)
 
   {
 
      if (is_readable(phpbb_realpath($sourcefile)))
 
      {
 
         $fd = fopen($sourcefile, "r");
 
         $contents = fread($fd, filesize($sourcefile));
 
         $encoded = $this->myChunkSplit(base64_encode($contents));
 
         fclose($fd);
 
      }
 
 
 
      return $encoded;
 
   }
 
 
 
} // class emailer
 
 
 
?>
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6.  <img src="./images/smilies/icon_cry.gif" alt=":cry:" title="Crying or Very sad" />
  7.  
  8. class emailer
  9.  
  10. {
  11.  
  12.    var $msg, $subject, $extra_headers;
  13.  
  14.    var $addresses, $reply_to, $from;
  15.  
  16.    var $use_smtp;
  17.  
  18.  
  19.  
  20.    var $tpl_msg = array();
  21.  
  22.  
  23.  
  24.    function emailer($use_smtp)
  25.  
  26.    {
  27.  
  28.       $this->reset();
  29.  
  30.       $this->use_smtp = $use_smtp;
  31.  
  32.       $this->reply_to = $this->from = '';
  33.  
  34.    }
  35.  
  36.  
  37.  
  38.    // Resets all the data (address, template file, etc etc to default
  39.  
  40.    function reset()
  41.  
  42.    {
  43.  
  44.       $this->addresses = array();
  45.  
  46.       $this->vars = $this->msg = $this->extra_headers = '';
  47.  
  48.    }
  49.  
  50.  
  51.  
  52.    // Sets an email address to send to
  53.  
  54.    function email_address($address)
  55.  
  56.    {
  57.  
  58.       $this->addresses['to'] = trim($address);
  59.  
  60.    }
  61.  
  62.  
  63.  
  64.    function cc($address)
  65.  
  66.    {
  67.  
  68.       $this->addresses['cc'][] = trim($address);
  69.  
  70.    }
  71.  
  72.  
  73.  
  74.    function bcc($address)
  75.  
  76.    {
  77.  
  78.       $this->addresses['bcc'][] = trim($address);
  79.  
  80.    }
  81.  
  82.  
  83.  
  84.    function replyto($address)
  85.  
  86.    {
  87.  
  88.       $this->reply_to = trim($address);
  89.  
  90.    }
  91.  
  92.  
  93.  
  94.    function from($address)
  95.  
  96.    {
  97.  
  98.       $this->from = trim($address);
  99.  
  100.    }
  101.  
  102.  
  103.  
  104.    // set up subject for mail
  105.  
  106.    function set_subject($subject = '')
  107.  
  108.    {
  109.  
  110.       $this->subject = trim(preg_replace('#[\n\r]+#s', '', $subject));
  111.  
  112.    }
  113.  
  114.  
  115.  
  116.    // set up extra mail headers
  117.  
  118.    function extra_headers($headers)
  119.  
  120.    {
  121.  
  122.       $this->extra_headers .= trim($headers) . "\n";
  123.  
  124.    }
  125.  
  126.  
  127.  
  128.    function use_template($template_file, $template_lang = '')
  129.  
  130.    {
  131.  
  132.       global $board_config, $phpbb_root_path;
  133.  
  134.  
  135.  
  136.       if (trim($template_file) == '')
  137.  
  138.       {
  139.  
  140.          message_die(GENERAL_ERROR, 'No template file set', '', __LINE__, __FILE__);
  141.  
  142.       }
  143.  
  144.  
  145.  
  146.       if (trim($template_lang) == '')
  147.  
  148.       {
  149.  
  150.          $template_lang = $board_config['default_lang'];
  151.  
  152.       }
  153.  
  154.  
  155.  
  156.       if (empty($this->tpl_msg[$template_lang . $template_file]))
  157.  
  158.       {
  159.  
  160.          $tpl_file = $phpbb_root_path . 'language/lang_' . $template_lang . '/email/' . $template_file . '.tpl';
  161.  
  162.  
  163.  
  164.          if (!@file_exists(@phpbb_realpath($tpl_file)))
  165.  
  166.          {
  167.  
  168.             $tpl_file = $phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/email/' . $template_file . '.tpl';
  169.  
  170.  
  171.  
  172.             if (!@file_exists(@phpbb_realpath($tpl_file)))
  173.  
  174.             {
  175.  
  176.                message_die(GENERAL_ERROR, 'Could not find email template file :: ' . $template_file, '', __LINE__, __FILE__);
  177.  
  178.             }
  179.  
  180.          }
  181.  
  182.  
  183.  
  184.          if (!($fd = @fopen($tpl_file, 'r')))
  185.  
  186.          {
  187.  
  188.             message_die(GENERAL_ERROR, 'Failed opening template file :: ' . $tpl_file, '', __LINE__, __FILE__);
  189.  
  190.          }
  191.  
  192.  
  193.  
  194.          $this->tpl_msg[$template_lang . $template_file] = fread($fd, filesize($tpl_file));
  195.  
  196.          fclose($fd);
  197.  
  198.       }
  199.  
  200.  
  201.  
  202.       $this->msg = $this->tpl_msg[$template_lang . $template_file];
  203.  
  204.  
  205.  
  206.       return true;
  207.  
  208.    }
  209.  
  210.  
  211.  
  212.    // assign variables
  213.  
  214.    function assign_vars($vars)
  215.  
  216.    {
  217.  
  218.       $this->vars = (empty($this->vars)) ? $vars : $this->vars . $vars;
  219.  
  220.    }
  221.  
  222.  
  223.  
  224.    // Send the mail out to the recipients set previously in var $this->address
  225.  
  226.    function send()
  227.  
  228.    {
  229.  
  230.       global $board_config, $lang, $phpEx, $phpbb_root_path, $db;
  231.  
  232.  
  233.  
  234.       // Escape all quotes, else the eval will fail.
  235.  
  236.       $this->msg = str_replace ("'", "\'", $this->msg);
  237.  
  238.       $this->msg = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "' . $\\1 . '", $this->msg);
  239.  
  240.  
  241.  
  242.       // Set vars
  243.  
  244.       reset ($this->vars);
  245.  
  246.       while (list($key, $val) = each($this->vars))
  247.  
  248.       {
  249.  
  250.          $$key = $val;
  251.  
  252.       }
  253.  
  254.  
  255.  
  256.       eval("\$this->msg = '$this->msg';");
  257.  
  258.  
  259.  
  260.       // Clear vars
  261.  
  262.       reset ($this->vars);
  263.  
  264.       while (list($key, $val) = each($this->vars))
  265.  
  266.       {
  267.  
  268.          unset($$key);
  269.  
  270.       }
  271.  
  272.  
  273.  
  274.       // We now try and pull a subject from the email body ... if it exists,
  275.  
  276.       // do this here because the subject may contain a variable
  277.  
  278.       $drop_header = '';
  279.  
  280.       $match = array();
  281.  
  282.       if (preg_match('#^(Subject:(.*?))$#m', $this->msg, $match))
  283.  
  284.       {
  285.  
  286.          $this->subject = (trim($match[2]) != '') ? trim($match[2]) : (($this->subject != '') ? $this->subject : 'No Subject');
  287.  
  288.          $drop_header .= '[\r\n]*?' . phpbb_preg_quote($match[1], '#');
  289.  
  290.       }
  291.  
  292.       else
  293.  
  294.       {
  295.  
  296.          $this->subject = (($this->subject != '') ? $this->subject : 'No Subject');
  297.  
  298.       }
  299.  
  300.  
  301.  
  302.       if (preg_match('#^(Charset:(.*?))$#m', $this->msg, $match))
  303.  
  304.       {
  305.  
  306.          $this->encoding = (trim($match[2]) != '') ? trim($match[2]) : trim($lang['ENCODING']);
  307.  
  308.          $drop_header .= '[\r\n]*?' . phpbb_preg_quote($match[1], '#');
  309.  
  310.       }
  311.  
  312.       else
  313.  
  314.       {
  315.  
  316.          $this->encoding = trim($lang['ENCODING']);
  317.  
  318.       }
  319.  
  320.  
  321.  
  322.       if ($drop_header != '')
  323.  
  324.       {
  325.  
  326.          $this->msg = trim(preg_replace('#' . $drop_header . '#s', '', $this->msg));
  327.  
  328.       }
  329.  
  330.  
  331.  
  332.       $to = $this->addresses['to'];
  333.  
  334.  
  335.  
  336.       $cc = (count($this->addresses['cc'])) ? implode(', ', $this->addresses['cc']) : '';
  337.  
  338.       $bcc = (count($this->addresses['bcc'])) ? implode(', ', $this->addresses['bcc']) : '';
  339.  
  340.  
  341.  
  342.       // Build header
  343.  
  344.       $this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\nMessage-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\nX-MimeOLE: Produced By phpBB2\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '')  . (($bcc != '') ? "Bcc: $bcc\n" : '');
  345.  
  346.  
  347.  
  348.       // Send message ... removed $this->encode() from subject for time being
  349.  
  350.       if ( $this->use_smtp )
  351.  
  352.       {
  353.  
  354.          if ( !defined('SMTP_INCLUDED') )
  355.  
  356.          {
  357.  
  358.             include($phpbb_root_path . 'includes/smtp.' . $phpEx);
  359.  
  360.          }
  361.  
  362.  
  363.  
  364.          $result = smtpmail($to, $this->subject, $this->msg, $this->extra_headers);
  365.  
  366.       }
  367.  
  368.       else
  369.  
  370.       {
  371.  
  372.          $empty_to_header = ($to == '') ? TRUE : FALSE;
  373.  
  374.          $to = ($to == '') ? (($board_config['sendmail_fix']) ? ' ' : 'Undisclosed-recipients:;') : $to;
  375.  
  376.    
  377.  
  378.          $result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
  379.  
  380.          
  381.  
  382.          if (!$result && !$board_config['sendmail_fix'] && $empty_to_header)
  383.  
  384.          {
  385.  
  386.             $to = ' ';
  387.  
  388.  
  389.  
  390.             $sql = "UPDATE " . CONFIG_TABLE . "
  391.  
  392.                SET config_value = '1'
  393.  
  394.                WHERE config_name = 'sendmail_fix'";
  395.  
  396.             if (!$db->sql_query($sql))
  397.  
  398.             {
  399.  
  400.                message_die(GENERAL_ERROR, 'Unable to update config table', '', __LINE__, __FILE__, $sql);
  401.  
  402.             }
  403.  
  404.  
  405.  
  406.             $board_config['sendmail_fix'] = 1;
  407.  
  408.             $result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
  409.  
  410.          }
  411.  
  412.       }
  413.  
  414.  
  415.  
  416.       // Did it work?
  417.  
  418.       if (!$result)
  419.  
  420.       {
  421.  
  422.          message_die(GENERAL_ERROR, 'Failed sending email :: ' . (($this->use_smtp) ? 'SMTP' : 'PHP') . ' :: ' . $result, '', __LINE__, __FILE__);
  423.  
  424.       }
  425.  
  426.  
  427.  
  428.       return true;
  429.  
  430.    }
  431.  
  432.  
  433.  
  434.    // Encodes the given string for proper display for this encoding ... nabbed
  435.  
  436.    // from php.net and modified. There is an alternative encoding method which
  437.  
  438.    // may produce lesd output but it's questionable as to its worth in this
  439.  
  440.    // scenario IMO
  441.  
  442.    function encode($str)
  443.  
  444.    {
  445.  
  446.       if ($this->encoding == '')
  447.  
  448.       {
  449.  
  450.          return $str;
  451.  
  452.       }
  453.  
  454.  
  455.  
  456.       // define start delimimter, end delimiter and spacer
  457.  
  458.       $end = "?=";
  459.  
  460.       $start = "=?$this->encoding?B?";
  461.  
  462.       $spacer = "$end\r\n $start";
  463.  
  464.  
  465.  
  466.       // determine length of encoded text within chunks and ensure length is even
  467.  
  468.       $length = 75 - strlen($start) - strlen($end);
  469.  
  470.       $length = floor($length / 2) * 2;
  471.  
  472.  
  473.  
  474.       // encode the string and split it into chunks with spacers after each chunk
  475.  
  476.       $str = chunk_split(base64_encode($str), $length, $spacer);
  477.  
  478.  
  479.  
  480.       // remove trailing spacer and add start and end delimiters
  481.  
  482.       $str = preg_replace('#' . phpbb_preg_quote($spacer, '#') . '$#', '', $str);
  483.  
  484.  
  485.  
  486.       return $start . $str . $end;
  487.  
  488.    }
  489.  
  490.  
  491.  
  492.    //
  493.  
  494.    // Attach files via MIME.
  495.  
  496.    //
  497.  
  498.    function attachFile($filename, $mimetype = "application/octet-stream", $szFromAddress, $szFilenameToDisplay)
  499.  
  500.    {
  501.  
  502.       global $lang;
  503.  
  504.       $mime_boundary = "--==================_846811060==_";
  505.  
  506.  
  507.  
  508.       $this->msg = '--' . $mime_boundary . "\nContent-Type: text/plain;\n\tcharset=\"" . $lang['ENCODING'] . "\"\n\n" . $this->msg;
  509.  
  510.  
  511.  
  512.       if ($mime_filename)
  513.  
  514.       {
  515.  
  516.          $filename = $mime_filename;
  517.  
  518.          $encoded = $this->encode_file($filename);
  519.  
  520.       }
  521.  
  522.  
  523.  
  524.       $fd = fopen($filename, "r");
  525.  
  526.       $contents = fread($fd, filesize($filename));
  527.  
  528.  
  529.  
  530.       $this->mimeOut = "--" . $mime_boundary . "\n";
  531.  
  532.       $this->mimeOut .= "Content-Type: " . $mimetype . ";\n\tname=\"$szFilenameToDisplay\"\n";
  533.  
  534.       $this->mimeOut .= "Content-Transfer-Encoding: quoted-printable\n";
  535.  
  536.       $this->mimeOut .= "Content-Disposition: attachment;\n\tfilename=\"$szFilenameToDisplay\"\n\n";
  537.  
  538.  
  539.  
  540.       if ( $mimetype == "message/rfc822" )
  541.  
  542.       {
  543.  
  544.          $this->mimeOut .= "From: ".$szFromAddress."\n";
  545.  
  546.          $this->mimeOut .= "To: ".$this->emailAddress."\n";
  547.  
  548.          $this->mimeOut .= "Date: ".date("D, d M Y H:i:s") . " UT\n";
  549.  
  550.          $this->mimeOut .= "Reply-To:".$szFromAddress."\n";
  551.  
  552.          $this->mimeOut .= "Subject: ".$this->mailSubject."\n";
  553.  
  554.          $this->mimeOut .= "X-Mailer: PHP/".phpversion()."\n";
  555.  
  556.          $this->mimeOut .= "MIME-Version: 1.0\n";
  557.  
  558.       }
  559.  
  560.  
  561.  
  562.       $this->mimeOut .= $contents."\n";
  563.  
  564.       $this->mimeOut .= "--" . $mime_boundary . "--" . "\n";
  565.  
  566.  
  567.  
  568.       return $out;
  569.  
  570.       // added -- to notify email client attachment is done
  571.  
  572.    }
  573.  
  574.  
  575.  
  576.    function getMimeHeaders($filename, $mime_filename="")
  577.  
  578.    {
  579.  
  580.       $mime_boundary = "--==================_846811060==_";
  581.  
  582.  
  583.  
  584.       if ($mime_filename)
  585.  
  586.       {
  587.  
  588.          $filename = $mime_filename;
  589.  
  590.       }
  591.  
  592.  
  593.  
  594.       $out = "MIME-Version: 1.0\n";
  595.  
  596.       $out .= "Content-Type: multipart/mixed;\n\tboundary=\"$mime_boundary\"\n\n";
  597.  
  598.       $out .= "This message is in MIME format. Since your mail reader does not understand\n";
  599.  
  600.       $out .= "this format, some or all of this message may not be legible.";
  601.  
  602.  
  603.  
  604.       return $out;
  605.  
  606.    }
  607.  
  608.  
  609.  
  610.    //
  611.  
  612.    // Split string by RFC 2045 semantics (76 chars per line, end with \r\n).
  613.  
  614.    //
  615.  
  616.    function myChunkSplit($str)
  617.  
  618.    {
  619.  
  620.       $stmp = $str;
  621.  
  622.       $len = strlen($stmp);
  623.  
  624.       $out = "";
  625.  
  626.  
  627.  
  628.       while ($len > 0)
  629.  
  630.       {
  631.  
  632.          if ($len >= 76)
  633.  
  634.          {
  635.  
  636.             $out .= substr($stmp, 0, 76) . "\r\n";
  637.  
  638.             $stmp = substr($stmp, 76);
  639.  
  640.             $len = $len - 76;
  641.  
  642.          }
  643.  
  644.          else
  645.  
  646.          {
  647.  
  648.             $out .= $stmp . "\r\n";
  649.  
  650.             $stmp = "";
  651.  
  652.             $len = 0;
  653.  
  654.          }
  655.  
  656.       }
  657.  
  658.       return $out;
  659.  
  660.    }
  661.  
  662.  
  663.  
  664.    //
  665.  
  666.    // Split the specified file up into a string and return it
  667.  
  668.    //
  669.  
  670.    function encode_file($sourcefile)
  671.  
  672.    {
  673.  
  674.       if (is_readable(phpbb_realpath($sourcefile)))
  675.  
  676.       {
  677.  
  678.          $fd = fopen($sourcefile, "r");
  679.  
  680.          $contents = fread($fd, filesize($sourcefile));
  681.  
  682.          $encoded = $this->myChunkSplit(base64_encode($contents));
  683.  
  684.          fclose($fd);
  685.  
  686.       }
  687.  
  688.  
  689.  
  690.       return $encoded;
  691.  
  692.    }
  693.  
  694.  
  695.  
  696. } // class emailer
  697.  
  698.  
  699.  
  700. ?>

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.