Jump to content

help with mattfm.php uploading file error


onehairfatty

Recommended Posts

Hi,  I am using mattfm.php with my form however, even though the email works (sent to host server), the attachment is not sent, however in the mailbox, it highlights it as a attacement type email.  The code is as follows - what is wrong - any help is much appreciated, many thanks.

 

html=

 

<form action="/cgi-bin/mattfm.php" method="post" enctype="multipart/form-data">
  <input type="hidden" name="recipient" value="you@domain.com">
      <input type="hidden" name="redirect" value="http://domain.com/thankyou.htm">
        <p align="left"><br>
          <font size="2">Contact name</font>: <font size="2"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"></font><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          <input name="Contactname" type="text" size="30" maxlength="40">
          <img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          <font size="2"> E-mail address:</font><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          <input name="email" type="text" size="30" maxlength="40">
        </p>
        <p><font size="2">Grid Ref Start Position:</font> 
          <input name="posi" type="text" size="3" maxlength="3">
          <font size="2">Width:</font> 
          <input name="wid" type="text" size="3" maxlength="3">
          <font size="2">Height:</font> 
          <input name="het" type="text" size="3" maxlength="3">
          <font size="-10"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"></font><font color="#FF0000"><strong><a href="javascript;:" onClick="MM_openBrWindow('grid.htm','mabgrid','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');MM_goToURL('parent','uy.htm');return document.MM_returnValue">View 
          Grid:</a></strong></font><font size="-10"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          Block(s) <img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          Block(s)<img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"></font> 
          <font color="#0000FF" size="-10"></font></p>
        <p><font size="2">Link to Webiste:</font><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          <input type="text" name="linktowebsite" size="30" maxlength="40">
          <img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"></p>
        <p><font size="2">Image/Logo:</font><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          <input type=hidden name=fileuploads value="file1,file2">
	  <input type=file name=file1/>
          (Note: for files>5mb please email file and details to me@domain.com)</p>
        <p><font size="2">Link to Video:</font><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          <input name="linktovideo" type="text" size="30" maxlength="40">
          <img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><font size="2">or</font><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"></p>
        <p> <font size="2">Attach Video:</font><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          <input type=file name=file2/>
          (Note: for files>5mb please email file and details to me@domain.com) 
        </p>
        <p> </p>
        <p><font size="2"> Promotion Box: Text<img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"></font></p>
        <p> 
          <textarea name="promottext" type="text" cols="20" rows="5" wrap="virtual"></textarea>
          <img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          <img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"><img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
        </p>
        <p> 
          <input type="submit" value="Submit">
          <img src="Q%27s%20Web%20page/images/0.gif" width="8" height="8"> 
          <input type="reset" value="Clear Form" onClick="return confirm('Are you sure you want to reset the form?')">
        </p>
      </form>

 

 

 

and here is the php code: (note what do i type for $upload_dir  ?) many thanks

 

 

 

<?php
/*
Matt's FM (FormMail) - A form to mail perl script
Copyright (C) 2001 Matt Wilson <matt@mattsscripts.co.uk>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

/*
OK, configuration time

In the referers array you *need* to specify all the host referer address'
which you want to allow the script to let through, ie from mattsscripts.co.uk,
I would specify ('mattsscripts.co.uk', 'www.mattsscripts.co.uk') as to make
sure whether somebody was on www.mattsscripts.co.uk or mattsscripts.co.uk.

There are a variety of options the script understands, each with their own effect on the resulting
email or the process in general, see below. These can all be specified using an input tag within
your form, hidden input tags are also recognised.

recipient = address to send the mail to (can be a comma seperated list, eg "r1@host.com,r2@host.com" etc)
sender = the "From: ..." (or Reply-To:) section of the sent email
subject = subject of the email
redirect = web page to redirect the client to after the email has been sent succesfully
incomplete = web page to redirect the client to if he/she has not completed the form (see below)
required = a comma seperated list of required values/variables, if the user does not fill all of these
     fields in then they will be redirected to the "incomplete" config variable (see above), if
     the "incomplete" config variable is not set then a page will be shown explaining the error.
     An example can be seen just below of this field;
	<input type=hidden name=required value="email,name,surname">
fileuploads = this option is used to handle fileuploads, within this field specify a comma seperated list
	of the fields within your form that contain file uploads, see below for an example.
---- CUT HERE ----
<form enctype="multipart/form-data" action="mattfm.cgi" method=post>
<input type=hidden name=fileuploads value="file1,file2,file3">
<input type=file name=file1>
<input type=file name=file2>
<input type=file name=file3>
<input type=submit>
</form>
---- CUT HERE ----
See? its really not that hard...

this is one of the most important variables in the script, this formats the
email that you receive! Variables are placed within "<" and ">" markers.
The variable name is placed within them and is case sensitive. POST and GET
variables are checked first, if they don't exist the script turns to
cookies, and finally environment variables.
A list of script defined variables is below

senttime => Time at which the EMail was sent
all_vars => Displays a list of all variables past to the script (not environment vars)

A full list of common environment variables is available below (but not always used!);

REMOTE_PORT => The port on which the requesting browser made the connection to the server
REMOTE_HOST => Remote hostname of the requesting client
REMOTE_ADDR => Remote IP address of the requesting client

SERVER_ADDR => The IP address of the web server
SERVER_PROTOCOL => Protocol used for this request (ie HTTP/1.1)
SERVER_SIGNATURE => Signature of the web server (eg Apache/1.3.23 Server at www.mattsscripts.co.uk Port 80)
SERVER_SOFTWARE => Software identification of the web servre (eg Apache/1.3.23 (Unix) PHP/4.1.1 mod_fastcgi/2.2.10 FrontPage/5.0.2.2510 mod_ssl/2.8.6 OpenSSL/0.9.6c)
SERVER_ADMIN => EMail address of the web server administrator (eg webmaster@mattsscripts.co.uk)
SERVER_NAME => Name of the web server (eg www.mattsscripts.co.uk)
SERVER_PORT => Port of which the web server request occured (eg 80)

GATEWAY_INTERFACE => Interface used for executing the script (eg CGI/1.1)
QUERY_STRING => The GET query string for the CGI script

HTTP_ACCEPT_LANGUAGE => Languages accepted by the server/script
HTTP_CONNECTION => Connection status requested by browser (ie keep-alive)
HTTP_ACCEPT => MIME types which the browser/server recognises (eg text/html)
HTTP_USER_AGENT => Identification of the browser (eg Mozilla/5.0)
HTTP_HOST => Server hostname (eg www.mattsscripts.co.uk)
HTTP_ACCEPT_ENCODING => Various encoding types accepted by the servre (eg gzip, deflate, compress;q=0.9)
HTTP_ACCEPT_CHARSET => Character sets accepted by web server (eg ISO-8859-1, utf-8;q=0.66, *;q=0.66)
HTTP_COOKIE => Full cookie string as sent by browser
HTTP_KEEP_ALIVE => Keep alive time for the ewb server connection (eg 300)

SCRIPT_NAME => Name of the script being executed (eg /cgi-bin/mattfm.cgi)
SCRIPT_FILENAME => Full path to the script being executed on the server (eg /home/mattsscripts.co.uk/cgi-bin/mattfm.cgi)

DOCUMENT_ROOT => Full path to executing script's directory (eg /home/mattsscripts.co.uk)

REQUEST_URI => Path of script requested by remote client (eg /cgi-bin/mattfm.cgi)
REQUEST_METHOD => Method used by remote client's browser to access the script (eg GET)

PATH => Environment shell execution path (eg /usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin)
*/

$email_format = '
Here is the result of your feedback form, sent @ <$senttime>

<$all_vars>

I\'m redirecting them to <$redirect> right now...

--- User information
Browser: <$HTTP_USER_AGENT>
Remote Host: <$REMOTE_HOST> <$REMOTE_ADDR>
---

Powered by Matt FM, it\'s free, so please feel free to use it -Matt
Available at http://www.mattsscripts.co.uk/mattfm.htm

';	//////////////// THIS LINE IS THE END OF THE EMAIL ////////////////

// what email type should we use?
//$email_type = 'html';
$email_type = 'plain';	// default to text, use html is you must though

// this is to specify the recipient in here rather than the form
$recipient = ''; // eg. $recipient = 'someguy@name.com,someguy2@name2.com'

// this tells the script to use `sendmail' (1) or an SMTP server (0)
//$useapp = 1;

// this is the app to use (works with sendmail atm)
//$mailapp = '/usr/sbin/sendmail';

// set this to your SMTP server (send mail server)
//$smtp = 'mail.domain.com';

// should we watch what the data returns and check it against values? (try 0 if
// you get an error about the SMTP returning incorrect values)
//$strict_smtp = 1;

// this represents a list of any variables that should be forwarded to the
// redirect page; $redirect?var1=data&var2=data...
// leave empty not to forward any
$forward = array( 'subject', 'email' );

// this is a comma seperated list of hosts that are allowed to post to this
// script, best to make sure
$referers = array('www.domain.com','domain.com');

// this option decides how to check the referer of the form
// 0 = don't check it (let all through)
// 1 = check it if the variable exists ($HTTP_REFERER)
// 2 = always check it, if the variable isn't there then tough
$referer_check = 2;

// when finished, this variable will tell the script whether or not to store any
// uploaded files on the server or whether to BASE64 encode them and attach them
// to the e-mail sent to "recipient" (use 1 file attachment - this is the only
// mode supported at the moment)
$upload_files = 0;

// if you answered 1 to the above variable then you need to use this in order to
// tell the script where it can safely upload the files (full path name
// preferably, but not needed - ensure the trailing slash!)
$upload_dir = 'http://www.domain.com/upfile/';

//////////////// GPG encryption config ////////////////

// use it? (1/0 = yes/no)
$gpg_use = 0;

// the binary path (full path)
$gpg_bin = '/usr/bin/gpg';

// any extra options? ascii coding and encryption are likely 
$gpg_extra_options = '-a -e --always-trust --no-tty';

// key of the recipient
$gpg_recipient = 'matt@mattsscripts.co.uk';

// a temp directory, somewhere we have write access to (with the trailing slash)
$gpg_temp = '/tmp/';

// the GPG config directory
$gpg_config = '/home/matt/.gnupg';

// OK, thats all
// =============

$message = '';
$fileuploads = array();
$numfileattachments = 0;
$attachments = '';
$senttime = senttime();
$required = '';
$sender = '';
$subject = '';
$redirect = '';

// this lump of code should sort out register_globals="off" problems 
global $vars;

if(!isset($_SERVER)) { $_SERVER = $HTTP_SERVER_VARS; }
if(!isset($_POST)) { $_POST = $HTTP_POST_VARS; }
if(!isset($_GET)) { $_GET = $HTTP_GET_VARS; }
if(!isset($_COOKIE)) { $_COOKIE = $HTTP_COOKIE_VARS; }
if(!isset($_FILES)) { $_FILES = $HTTP_POST_FILES; }
if(!isset($_ENV)) { $_ENV = $HTTP_ENV_VARS; }
if(!isset($_SESSION)) { $_SESSION = $HTTP_SESSION_VARS; }

while(list($key, $var) = each($_GET)) { $vars[$key] = $var; }
while(list($key, $var) = each($_POST)) { $vars[$key] = $var; }

get_details();
check_details();
message_construct();

// make sure we've got a valid email type
if(!isset($email_type) or ($email_type != 'html' and $email_type != 'plain')) {
$email_type = 'plain';
}

// we need to generate a random boundary, so let's
$boundary = '';
$rands = array(
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
"R","S","T","U","V","W","X","Y","Z","0","9","8","7","6","5","4","3",
"2","1");

srand((double)microtime()*1000000 );

do {
$s = sizeof($rands);
for($l=1; $l<=32; ++$l){ 
	//$boundary .= $rands[rand()*$s];
	$boundary .= $rands[rand(0,$s-1)];
}
} while(strpos($message, $boundary) or strpos($attachments, $boundary));

if($upload_files == 0) {
handle_uploads();
}
//if($useapp == 1) {
//	sendmail_app();
//} else {
//	sendmail_smtp();
//}
sendmail_php();

if(!strlen($redirect)){
sentok();
} else {
if(sizeof($forward)) {
	$redirect .= '?';
	for($l=0; $l<sizeof($forward); ++$l) {
		$redirect .= urlencode($forward[$l]).'='.urlencode($vars[$forward[$l]]).'&';
	}
	$redirect = preg_replace("'&$'", "", $redirect);
}
header("Location: ".$redirect);
}

exit();

function senttime() {
return date("D, d M Y H:i:s O", time()+($tdif*3600));
}

function bad_recipient() {
echo	'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Bad recipient supplied</title>
</head>
<body>
<h3 align="center">Unable to send email because one or more of the recipient e-mail address supplied was invalid.</h3>
<font face="verdana" size="3"><div align="center">Please contact the webmaster and report this error.</div></font>
<h6>Powered by Matt FM available <a href="http://www.mattsscripts.co.uk/mattfm.htm">here</a>, it\'s free, so please feel free to use it. -Matt</h6>
</body>
</html>
';

        exit();
}

function no_recipient() {
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>No recipient supplied</title>
</head>
<body>
<h3 align="center">Unable to send email because no recipient address was supplied.</h3>
<font face="verdana" size="3"><div align="center">Please contact the webmaster and report this error.</div></font>
<h6>Powered by Matt FM available <a href="http://www.mattsscripts.co.uk/mattfm.htm">here</a>, it\'s free, so please feel free to use it. -Matt</h6>
</body>
</html>
';

        exit();
}

function gpg_encrypt($mes) {
global $gpg_temp;
global $gpg_config;
global $gpg_bin;
global $gpg_extra_options;
global $gpg_recipient;

$l=0;
while(file_exists($gpg_temp.'mattfm.'.$l)) { $l++; }
$tmp_file = $gpg_temp.'mattfm.'.$l;

$fd = popen($gpg_bin.' --homedir '.$gpg_config.' '.$gpg_extra_options.' -r "'.$gpg_recipient.'" -o '.$tmp_file, "w");
fputs($fd, $mes);

$buf = @implode("", @file($tmp_file));

unlink($tmp_file);
return $buf;
}

function sendmail_php() {
global $recipient;
global $subject;
global $_ENV;
global $sender;
global $senttime;
global $email_type;
global $boundary;
global $attachments;
global $message;

if(!$recipient){
	no_recipient();
}
if(!$subject){
	$subject = "Matt FM feedback form";
}

$host = $_ENV['HTTP_HOST'];
if($host == '') {
	$host = $recipient;
	$host = preg_replace('/^.*@/', "", $host);
	$host = preg_replace('/^,*$/', "", $host);
} else {
	$host = preg_replace('/^www\./i', "", $host);
}

// make sure the sender is set and that it's a valid email address
if(!$sender or !preg_match('/^[[0-9]|[a-z]|\-|\_|\.]{2,}\@[[0-9]|[a-z]|\-]+\.[[0-9]|[a-z]|\-|\.]+$/s', $sender)){
	$sender = "noreply@".$host;
}

$recipients = split(',', $recipient);
$mrecipients = array();
for($l=0; $l<sizeof($recipients); ++$l) {
	$r = $recipients[$l];
	// make sure it's not a fake recipient e-mail address, if so then
	// we may as well bomb...
	if(!preg_match('/^[[0-9]|[a-z]|\-|\_|\.]{2,}\@[[0-9]|[a-z]|\-]+\.[[0-9]|[a-z]|\-|\.]+$/is', $r)) {
		bad_recipient();
	}
	$r = preg_replace('/(^\s)|(\s$)/', "", $r);
	$mrecipients[] = $r;
}

$headers =	"From: ".$sender."\n".
		//"Subject: ".$subject."\n".
		"Date: ".$senttime."\n".
		"To: ".$recipient."\n".
		"X-Mailer: Matt's FormMail\n".
		"X-Mailer-URL: http://www.mattsscripts.co.uk/mattfm.htm\n".
		"MIME-Version: 1.0\n".
		"Content-type: multipart/mixed; charset=US-ASCII; boundary=".$boundary."\n\n".
		"--".$boundary."\n".
		"Content-Type: text/".$email_type."; charset=US-ASCII\n";

if($numfileattachments) {
	$message .= $attachments;
}
//$buf .= "\n".$boundary."\n\n";

if(!mail(implode(",", $mrecipients), $subject, $message, $headers)) {
	cant_send('viaapp');	
}
}

/*
function sendmail_smtp {
if(!$recipient){ &no_recipient; }
if(!$subject){ $subject = "Matt FM feedback form"; }

my $host = $ENV{'HTTP_HOST'};
if($host == '') {
	$host = $recipient;
	$host =~ s/^.*\@//g;
	$host =~ s/,.*$//g;
} else {
	$host =~ s/^www\.//i;
}

if(!$sender){ $sender = "noreply\@".$host; }

my $osock;
my $tmp;
my $dat = '';

my $proto = getprotobyname('tcp');
socket($osock, PF_INET, SOCK_STREAM, $proto)
	or &cant_send('viasmtp');
my $sin = sockaddr_in(25, inet_aton($smtp));
connect($osock,$sin)
	or &cant_send('viasmtp');

sysread $osock, $tmp, 2048;
// 220 xxxx.xxx ESMTP Sendmail x.x.x/x.x.x; Time/Date
if($tmp !~ m/^220/ and $strict_smtp == 1){ &smtp_error; }
$dat .= $tmp;

//	$buf = "helo ".$host."\nmail from: ".$sender."\n";
syswrite $osock, "HELO ".$host."\r\n", length("HELO ".$host."\r\n");
sysread $osock, $tmp, 2048;
// 250 xxxx.xxx Hello <hostname> [xxx.xxx.xxx.xxx], pleased to meet you
if($tmp !~ m/^250/ and $strict_smtp == 1){ &smtp_error; }
$dat .= $tmp;

syswrite $osock, "MAIL FROM: ".$sender."\r\n", length("MAIL FROM: ".$sender."\r\n");
sysread $osock, $tmp, 2048;
// 250 xxx@xxxxxxxxxx... Sender ok
if($tmp !~ m/^250/ and $strict_smtp == 1){ &smtp_error; }
$dat .= $tmp;

my @recipients = split ',', $recipient;
foreach $recipient (@recipients){
	$recipient =~ s/(^\s)|(\s$)//g;
	syswrite $osock, "RCPT TO: ".$recipient."\r\n", length("RCPT TO: ".$recipient."\r\n");
	sysread $osock, $tmp, 2048;
// 250 xxx@xxxxxxx... Recipient ok
	if($tmp !~ m/^250/ and $strict_smtp == 1){ &smtp_error; }
	$dat .= $tmp;
//		$buf .= "rcpt to: ".$recipient."\n";
}

syswrite $osock, "DATA\r\n", 5;
sysread $osock, $tmp, 2048;
// 354 Enter mail, end with "." on a line by itself
if($tmp !~ m/^354/ and $strict_smtp == 1){ &smtp_error; }
$dat .= $tmp;

//	$buf .= "data\n".
my $buf =	"Subject: ".$subject."\n".
		"Date: ".$senttime."\n".
		"To: ".$recipient."\n".
		"X-Mailer: Matt's FormMail\n".
		"X-Mailer-URL: http://www.mattsscripts.co.uk/mattfm.htm\n".
		"MIME-Version: 1.0\n".
		"Content-type: multipart/mixed; charset=US-ASCII; boundary=".$boundary."\n\n".
		"--".$boundary."\n".
		"Content-Type: text/".$email_type."; charset=US-ASCII\n\n".
		$message;

if($numfileattachments) { $buf .= $attachments; }
//$buf .= "\n".$boundary."\n";

$buf =~ s/\n\.\n/\n\n/g;
$buf .= "\n\.\n";

my $off = 0;
my $len = length $buf;
while($len){
	my $w = syswrite $osock, $buf, $len, $off;
	$len -= $w;
	$off += $w;
}

sysread $osock, $tmp, 2048;
if($tmp !~ m/^250/ and $strict_smtp == 1){ &smtp_error; }
$dat .= $tmp;

syswrite $osock, "QUIT\r\n", 5;

close($osock);
}
*/
function check_details() {
global $referer_check;
global $_ENV;
global $referers;

if($referer_check > 0) {
	if(!$_ENV{'HTTP_REFERER'} and $referer_check == 1) { return; }

	// perform the check
	$referer = $_ENV{'HTTP_REFERER'};
	for($l=0; $l<sizeof($referers); ++$l) {
		if(preg_match('/^(http:\/\/)?('.$referers[$l].')/i', $referer) or preg_match('/^(https:\/\/)?('.$referers[$l].')/i', $referer)) {
			return;
		}
	}
	unauth_ref();
}
}

function get_details() {
global $required;
global $recipient;
global $sender;
global $subject;
global $redirect;
global $fileuploads;
global $vars;

if($recipient == "") {
	$recipient = $vars["recipient"];
}

$required = $vars["required"];
$sender = $vars["sender"];
$subject = $vars["subject"];
$redirect = $vars["redirect"];

$rf = split(",", $required);
for($l=0; $l<sizeof($rf); ++$l) {
	$rf[$l] = ereg_replace("(^\s)|(\s\$)", "", $rf[$l]);
	if($rf[$l] != "" && (!isset($vars[$rf[$l]]) || $vars[$rf[$l]] == "")) {
		incomplete();
	}
}

$fu = $vars["fileuploads"];
if(strpos($fu, ",")){
	$fileuploads = split(",", $fu);
} else {
	$fileuploads = array($fu);
}
}

function exists_in_array($s, $a) {
for($l=0; $l<sizeof($a); ++$l) {
	if($s == $a[$l]) {
		return 1;
	}
}
return 0;
}

function return_filename($fn) {
if(strpos($fn, "/")) {
	$fn = ereg_replace("^(.+)/", "", $fn);
} else {
	$fn = ereg_replace("^(.+)\\", "", $fn);
}
return $fn;
}

function handle_uploads() {
global $upload_files;
global $vars;
global $_FILES;
global $fileuploads;
global $gpg_use;
global $boundary;
global $numfileattachments;
global $upload_dir;

if($upload_files == 0) {
	for($l=0; $l<sizeof($fileuploads); ++$l) {
		$f = $fileuploads[$l];
		if(isset($_FILES[$f]['tmp_name'])) {
			$fd = @implode("", @file($_FILES[$f]['tmp_name']));
			$filename = return_filename($f);
			$numfileattachments++;
			if($gpg_use == 1) {
				$fd = gpg_encrypt($fd);
				$filename .= '.gpg';
			}
			$filename = str_replace(" ", "_", $filename);
			$attachments .=	"\n--".$boundary."\n".
					"Content-Type: octet/stream; name=".$filename."\n".
					"Content-Transfer-Encoding: BASE64\n".
					"Content-Description:\n".
					"Content-Disposition: attachment; filename=".$filename."\n\n".
					base64_encode($fd)."\n";
		}
	}
} else {
	for($l=0; $l<sizeof($fileuploads); ++$l) {
		$f = $fileuploads[$l];
		if(isset($_FILES[$f]['tmp_name'])) {
			$fd = @implode("", @file($_FILES[$f]['tmp_name']));
			$filename = return_filename($f);
			$time = time();
			while(mkdir($upload_dir.'MattFM'.$time, '755') != TRUE) {
				$message .= "\n(tried to create a directory for files called ".$upload_dir."MattFM".$time." but couldn't!\n";
				$time = time();
			}
			$savepath = $upload_dir.'MattFM'.$time.substr($upload_dir, -1).$filename;
			if(!copy($_FILES[$f]['tmp_name'], $savepath)) {
				$message .= "\ntried to upload file ".$filename.", but couldn't !!!\n";
			} else {
				$message .= "Uploaded file to : ".$savepath."\n";
			}
		}
	}
}
}

function message_construct() {
global $vars;
global $email_format;
global $_COOKIE;
global $_ENV;
global $gpg_use;
global $message;

$message = $email_format;

// make all necessary variable exchanges
while(preg_match('/<\$([0-9]|[a-z]|[A-Z]|_|\-|!>)+>/', $message, $matches)) {
	$var = $matches[0];

	$var = ereg_replace('^(<\$)|>$', '', $var);

	$val = '['.$var.' - undefined]';

	// firstly, is it an internal variable?
	if($var == "senttime") {
		$val = senttime();
	} else if ($var == "all_vars") {
		$val = '';
		while(list($key,$valt) = each($vars)) {
			$val .= "\"".$key."\" => \"".$valt."\"\n";
		}
	} else {
		// the variable is POST or GET, swap it
		if(isset($vars[$var])) {
			$val = $vars[$var];
		} else {
			// hrm, is it an environment variable?
			if(isset($_ENV[$var])) {
				// yup, make the change
				$val = $_ENV[$var];
			} else {
				// is it a cookie?
				if(isset($_COOKIE[$var])) {
					// yay
					$val = $_COOKIE[$var];
				}
			}
		}
	}

	$message = str_replace('<$'.$var.'>', $val, $message);
}

$message = str_replace("\n", "\r\n", $message);

if($gpg_use == 1) { $message = gpg_encrypt($message); }
return $message;
}

// the following commands all show different errors/success' details
function cant_send($via) {
global $smtp;
global $mailapp;

echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
';

if($via == "viasmtp") {
	echo	"<title>Unable to connect to smtp</title>",
		"<h3 align=\"center\">Unable to send email because I am unable to connect to the SMTP server located @ '", $smtp, "'</h3>";
} else {
	echo	"<title>Unable to use ", $mailapp, "</title>",
		"<h3 align=\"center\">Unable to use program '", $mailapp, "' to send mail!</h3>";
}

print	';
<font face="verdana" size="3"><div align="center">Please click <a href="javascript:window.back();">here</a> to go back and complete the form.</div></font>
<h6>Powered by Matt FM available <a href="http://www.mattsscripts.co.uk/mattfm.htm">here</a>, it\'s free, so please feel free to use it. -Matt</h6>
</body>
</html>
';

exit();
}

function smtp_error() {
global $smtp;

echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>SMTP error</title>
</head>
<body>
<h3 align="center">Unable to send email because the SMTP server located @ ', $smtp, ' did not send the correct response.</h3>
<font face="verdana" size="3"><div align="center">Please click <a href="javascript:window.back();">here</a> to go back and try again.</div></font>
<h6>Powered by Matt FM available <a href="http://www.mattsscripts.co.uk/mattfm.htm">here</a>, it\'s free, so please feel free to use it. -Matt</h6>
</body>
</html>
';

exit();
}

function unauth_ref() {
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Unauthorized referer!</title>
</head>
<body>
<h3 align="center">Unable to continue with this operation because the site which linked to here is not on the list of authorized sites</h3>
<h6>Powered by Matt FM available <a href="http://www.mattsscripts.co.uk/mattfm.htm">here</a>, it\'s free, so please feel free to use it. -Matt</h6>
</body>
</html>
';

exit();
}

function incomplete() {
global $vars;

if($vars["incomplete"]){
	header("Location: ".$vars["incomplete"]);
} else {
	echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Incomplete form</title>
</head>
<body>
<h3 align="center">Unable to continue due to the previous form being incomplete</h3>
<font face="verdana" size="3"><div align="center">Please click <a href="javascript:window.back();">here</a> to go back and complete the form.</div></font>
<h6>Powered by Matt FM available <a href="http://www.mattsscripts.co.uk/mattfm.htm">here</a>, it\'s free, so please feel free to use it. -Matt</h6>
</body>
</html>
';
}

exit();
}

function sentok() {
global $recipient;

echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Message sent</title>
</head>
<body>
<h3 align="center">Your message has been sent to ', $recipient, '</h3>
<font face="verdana" size="3"><div align="center">Please click <a href="javascript:window.back();">here</a> to go back to the page you just visited</div></font>
<h6>Powered by Matt FM available <a href="http://www.mattsscripts.co.uk/mattfm.htm">here</a>, it\'s free, so please feel free to use it. -Matt</h6>
</body>
</html>
';

exit();
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.