Log in

View Full Version : form data depending on php & xml



Cheng
09-29-2006, 05:41 AM
Hi.

I've got this Flash contact form where the data that has to be send to an e-mail address depends on a PHP and XML file.
It is possible to send the data to more than just one e-mail address and this looks like this in the XML file:

<hidden name="mailto" value="1st@e-mail.com; 2nd@e-mail.com" />
<hidden name="subject" value="Contact Form" />That's like a CC copy I would say.
But what I want is to send the data to the 2nd e-mail address like a BCC copy so that it is hidden and the receiver of 1st@e-mail.com can't see that 2nd@e-mail.com got the data as well.
Can this be done by just adding an entry to the XML file or does it require a modification to the PHP file as well?
The attachment includes the XML and PHP file and the form SWF and HTML file as well.
Please someone help me by explaining how to modify these files to make possible what has been described above.

Thank you very much.
Cheng

djr33
09-29-2006, 05:47 AM
That can't be done just with xml (unless there is some special trick to it, already coded into the php, which I really doubt.)

The easy way with php is just to repeat the function twice, using on address the first time, then the second the next, and the emails won't be BCCs.. they'll just be seperate emails.
Or, I think that the php mail() function may support bccs as a special attribute. Look on php.net for the mail function and see what extra attributes can be added.

Cheng
09-29-2006, 06:09 AM
Hi dir33.

Thanks for your reply.
The think is I don't know anything about PHP scripting that's why I ask for help here.
Could you please open the PHP file in the attachment and have a look at it and then point out to me where the changes have to be applied.
As I understand the XML file must be modified as well because the e-mail address is in the XML file and not in the PHP.
To start with the XML file would it be ok to just add another line like this one here?

Original
<hidden name="mailto" value="1st@e-mail.com; 2nd@e-mail.com" />
<hidden name="subject" value="Contact Form" /> Modified
<hidden name="mailto" value="1st@e-mail.com" />
<hidden name="mailto" value="2nd@e-mail.com" />
<hidden name="subject" value="Contact Form" /> If this is correct than there is only the PHP file left, if that's correct of course.

Thanks again.
Cheng

Here the PHP script:
<?php

/* Constants */
/* Version */ $version = '2.3';
/* Date */ $date = '09/28/05';
/* Error Level */ error_reporting(E_ALL & ~E_NOTICE);
/* Text File */ $saveFile = '[FILENAME]';

//...... Added UTF-8 support

//Config file must be in the same directory as this file
//and have the same first part of the name. i.e. myform.inc.php
list($formName,$ext) = split('\.',basename($_SERVER['PHP_SELF']),2);
if (file_exists($formName.".inc.php"))
{
include($formName.".inc.php");
}

//XML file must be in the same directory as this file
$debug = (isset($_REQUEST['debug'])) ? $_REQUEST['debug'] : $debug;
if ($debug) error_reporting(E_ALL);

//...... Display debugging information
if ($debug)
{
switch($debug)
{
case 'info' :
phpinfo();
exit();
break;

case 'version' :
err("Current MailForm version: <b>".$version."</b><br>Current PHP version: <b>".phpversion()."</b><br> Current Revision Date: <b>$date</b>");
break;
}
}


$date=date("l, F dS, Y \a\\t g:i a");
$server=$_SERVER['SERVER_NAME'];

$msg="Here is the information submitted to $formName from $_SERVER[REMOTE_ADDR] on $date\r\n\r\n------------------------\r\n";

//...... Make sure we keep the variables
$subject = $_REQUEST['subject'];
$thankyoupage = $_REQUEST['thankyoupage'];
$xmlFile = $_REQUEST['xmlfile'];
$unreg = $_REQUEST['uR'];
$email = $_REQUEST['eM'];

if (file_exists($xmlFile))
{
$fd = fopen(basename($xmlFile),'r');
while(!feof($fd))
{
$contents .= fgets($fd,1024);
}
fclose($fd);
}
else

djr33
09-29-2006, 07:28 AM
In the xml, there needs a different name for the second email field, like mailto2, as opposed to just mailto again.
This will just make two variables, then you can repeat the operation for both.

However, there's no command for mail() in the php you posted. It includes a couple files... but I'm not sure what they're named. I think one is config.php or something similar as that is referenced in a comment in the code, and another is added by an include.... $formName.php.inc, and I'm not seeing where $formName is defined, so not sure what the filename there is.

Anyway, nothing can be done without seeing the code...

Cheng
09-29-2006, 11:05 AM
Hi dir33.

Thanks again for your reply.
There is only the PHP code I've posted and also attached together with the other files in the thread starter.
The only think I found in the PHP is this:
$msg="Here is the information submitted to $formName from $_SERVER[REMOTE_ADDR] on $date\r\n\r\n------------------------\r\n";

//...... Make sure we keep the variables
$subject = $_REQUEST['subject'];
$thankyoupage = $_REQUEST['thankyoupage'];
$xmlFile = $_REQUEST['xmlfile'];
$unreg = $_REQUEST['uR'];
$email = $_REQUEST['eM'];Do you think something needs to be added here?
I'll try it now and enter mailto1 in the XML and see if that works.
If you got an idea how to do it please let me know.

Thanks again.
Cheng

djr33
09-29-2006, 09:59 PM
The thing is, you need a different variable/field name for the second email address, so you can access both seperately.
However, just doing that won't fix it since the php code needs to match as well.

The $msg line above defines the message (and I assume it later gets the actual message added to it).
The other lines are just passing the info along, in what appears to be the 2nd page of the process.
The $email, etc. variables are redefined with the $_REQUEST values from, I assume, the form. Just looks like it might be a multipage thing.
Anyway, that's all I can tell you about the above code.

What I need, to have any clue what's going on is:
1. Where the $formName variable is defined. Post the whole script that is from (take out passwords and such if you're worried about secuity, but we do need to see more than that)
and
2. the mail() function. This MUST exist, or it just won't send an email.

Cheng
09-30-2006, 04:09 AM
Hi dir33.

Thanks again for your help as I'm unable to do this alone.
The ZIP file attached to this post here contains all there is.
What you are referring to as 2nd page, that is mean that the form can be configured to send a copy of the data to the person who submits the form but this isn't configured in this case here.
The code for this feature is just predefined in the PHP script no matter how the form is configured in the program, the PHP code is always the same and the details are specified in the XML file like the form name e-mail address etc.
There are no passwords and I don't hold back anything.
There are just these 4 files the HTML, SWF, PHP and XML.
That's all there is.
As I see it the XML file contains only this for the e-mail to send:
<hidden name="mailto" value="1st@e-mail.com; 2nd@e-mail.com" />
<hidden name="subject" value="Contakt-Form" /> The PHP variables for the e-mail I think are in here:
//...... Make sure we keep the variables
$subject = $_REQUEST['subject'];
$thankyoupage = $_REQUEST['thankyoupage'];
$xmlFile = $_REQUEST['xmlfile'];
$unreg = $_REQUEST['uR'];
$email = $_REQUEST['eM'];I tried to make changes here but couldn't get it to work as I don't understand coding.
As I said everything there is, is in the attached ZIP file.
If you can't figure it out as well how to send the form data to a 2nd e-mail address other than by CC copy you might know where I can ask for help.
It seems nobody else is in here is jumping in for help.

Thanks again very much.

Cheng

djr33
10-02-2006, 02:40 AM
Ok, I thought you had posted everything from the php file in the above post that was in the zip. Looking at the zip, there's a lot more.


<?php
/****************************************************/
/* CoffeeCup Software Form to Mail program */
/* (C) 2005 CoffeeCup Software */
/****************************************************/
/* - Companion Program For Coffeecup Form Builder - */
/* Visit - http://www.coffeecup.com */
/****************************************************/
/* Constants */
/* Version */ $version = '2.3';
/* Date */ $date = '09/28/05';
/* Error Level */ error_reporting(E_ALL & ~E_NOTICE);
/* Text File */ $saveFile = '[FILENAME]';

//...... Added UTF-8 support

//Config file must be in the same directory as this file
//and have the same first part of the name. i.e. myform.inc.php
list($formName,$ext) = split('\.',basename($_SERVER['PHP_SELF']),2);
if (file_exists($formName.".inc.php"))
{
include($formName.".inc.php");
}

//XML file must be in the same directory as this file
$debug = (isset($_REQUEST['debug'])) ? $_REQUEST['debug'] : $debug;
if ($debug) error_reporting(E_ALL);

//...... Display debugging information
if ($debug)
{
switch($debug)
{
case 'info' :
phpinfo();
exit();
break;

case 'version' :
err("Current MailForm version: <b>".$version."</b><br>Current PHP version: <b>".phpversion()."</b><br> Current Revision Date: <b>$date</b>");
break;
}
}


$date=date("l, F dS, Y \a\\t g:i a");
$server=$_SERVER['SERVER_NAME'];

$msg="Here is the information submitted to $formName from $_SERVER[REMOTE_ADDR] on $date\r\n\r\n------------------------\r\n";

//...... Make sure we keep the variables
$subject = $_REQUEST['subject'];
$thankyoupage = $_REQUEST['thankyoupage'];
$xmlFile = $_REQUEST['xmlfile'];
$unreg = $_REQUEST['uR'];
$email = $_REQUEST['eM'];

if (file_exists($xmlFile))
{
$fd = fopen(basename($xmlFile),'r');
while(!feof($fd))
{
$contents .= fgets($fd,1024);
}
fclose($fd);
}
else
{
err("No &lt;xml&gt; data file found<br>Please upload the data xml file ".$_REQUEST['xmlfile']);
}

$file_info = preg_replace("/\r|\n/"," ",$contents);

//...... Includes the form results in your thank you page
$incresults = (preg_match('/<form.*?includeresults="true".*?>/',$file_info));

//...... Sends email of form results to the user
$emailusr = (preg_match('/<form.*?emailuser="true".*?>/',$file_info));

preg_match('/<hidden.*?name="mailto".*?value="(.*?)".*?>/',$file_info,$matches);
$mailto = $matches[1];

preg_match('/<hidden.*?name="thankyoumessage".*?value="(.*?)".*?>/',$file_info,$matches2);
$thanksMsg = unhtmlentities($matches2[1]);


preg_match('/<form.*?bkcolor2="(.*?)".*?>/',$file_info,$matches3);
$backgroundclr = $matches3[1];

preg_match('/<form.*?fontcolor2="(.*?)".*?>/',$file_info,$matches4);
$fontclr = $matches4[1];

preg_match('/<form.*?autoresponse="(.*?)".*?>/',$file_info,$matches5);
$autoresponse = $matches5[1];

if(!$thanksMsg)
{
$thanksMsg="Thank you for your form submission!";
}

if(!$subject)
{
$subject="Form Submission";
}


//...... Reversing array elements so they appear in correct form order
$_REQVARS = array_merge($_POST,$_GET);

//...... Delete them from the request array, we won't need
//...... to send these in the actual email.
unset($_REQVARS['thankyoupage']);
unset($_REQVARS['subject']);
unset($_REQVARS['mailto']);
unset($_REQVARS['xmlfile']);
unset($_REQVARS['thankyoumessage']);
unset($_REQVARS['uR']);
unset($_REQVARS['eM']);


$addtoThank.="<span><p align=\"center\">Below is the information you submitted:</br></br></p><p align=\"center\">";
$txtmsg=$formName.'|'.date("Y-m-d H:i:s").'|'.$_SERVER['REMOTE_ADDR'].'|';

$_REQVARS=array_reverse($_REQVARS);

foreach($_REQVARS as $key=>$value)
{
$msg .= "$key: ".stripslashes($value)."\r\n\r\n";
$addtoThank.="$key: ".stripslashes($value)."<br/>";
$txtmsg .= "$key: ".stripslashes($value)."|";
}

$addtoThank.="</p></span>";
$addtoThank=str_replace("_"," ",$addtoThank);

//...... Write to the text file here
if ($saveFile != '[FILENAME]')
{
$fd = fopen($saveFile,"a+");
ccfputcsv($fd, $txtmsg);
fclose($fd);
}

if($unreg == 'true')
{
$unregMsg="<div align=\"center\"><font size=\"1\" face=\"Arial\">Created with CoffeeCup Form Builder <a href=\"http://www.coffeecup.com/\" target=\"_blank\" title=\"CoffeeCup Form Builder\">Download It Here</a></font></div>";
$msg .= "------------------------\r\n\r\nThis Form was sent to you using CoffeeCup Form Builder.\r\nPlease tell a friend about us: http://www.coffeecup.com/form-builder/\r\n";
}
else
{
$unregMsg = '';
}

//...... Why are we converting underscores to spaces?
$newMsg=str_replace("_"," ",$msg) . $autoresponse;

//...... Construct a proper mime/UTF-8 for extended ASCII, and internationalization
$headers = "MIME-Version: 1.0\r\n" . "Content-type: text/plain; charset=UTF-8\r\n\r\n";

//...... If they specify "email" in their form, it will set the reply-to field.
if($email)
{
$sentMail = mail($mailto,$subject,$newMsg,"Reply-To: $email\r\nFrom: $email\r\n$headers");

//...... MAIL TO USER
if($emailusr)
{
mail($email,$subject,$newMsg,"Reply-To: $mailto\r\n$headers");
}
}
//...... Send email as regular web server user
else
{
$sentMail = mail($mailto,$subject,$newMsg,$headers);
}

if (!$sentMail) err("Cannot send email!");

if(!$incresults)
{
$addtoThank="";
}

if($thankyoupage)
{
header("Location: $thankyoupage");
}
else
{
print <<<__EOT__
<html>

<head>
<title>Form Submitted</title>
<style type="text/css">
<!--
body {
background-color:$backgroundclr;
}
#message {
width:720px;
margin:9px auto;
text-align:center;
font:bold 14px 'Trebuchet MS',arial,helvetica,sans-serif;
color:$fontclr;
}
#message span {
font-weight:normal;
}
//-->
</style>
</head>

<body bgcolor="$background-color">
<center>
<div id="message"><div>$thanksMsg</div>
<br /><br />
$addtoThank
<br /><br />
$unregMsg
</center>
</body>

</html>
__EOT__;

}

function err($string)
{
global $version;
echo("<h2 style=\"font:normal 20px 'Trebuchet MS',arial\">$string</h2>");
echo("<h2 style=\"font:normal 12px 'Trebuchet MX',arial\">Either sendmail or smtp is not properly configured on your system.<br />Please contact your hosting provider to correct this problem.<!-- $version --></h2>");
exit();
}

function ccfputcsv($handle, $mymsg)
{
fputs($handle, $mymsg."\n");//stripslashes(substr($str, 0, -1))

return strlen($mymsg);
}

function unhtmlentities($string)
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}


?>
That's pretty complex. I get what's going on, but I wouldn't feel too safe about editing it without testing a lot, and I'm not exactly sure what the "correct" way to do that is.

Generally, it's not a very complex code.
1. Gets the data, puts it in the $REQVARS array.
2. Sets vars like $email from $REQVARS array.
3. Does safety stuff to variables.
4. sets headers for the email, like text encoding, etc.
5. Sends the email, using ifs to choose the right mail() function.

The fifth is the hardest part.
First you'd need to just follow the $email value through the script and use, for example, $email2 as the second email. Copy all the steps.
Then you'd take each of the if/mail() functions and add a second one, to the second user.
However, i'm not quite sure what all of the different options are for the mail()/if choices, so not sure what do to there.

so...
what is this? what's it for? who's using it? why do you need it to be bcc, not cc?

djr33
10-02-2006, 03:01 AM
Well.... maybe it isn't that complex.
Here's my test....
NOTE: Name the second for the email in your xml/form/whatever mailto2. (the first email should be called mailto).

<?php
/****************************************************/
/* CoffeeCup Software Form to Mail program */
/* (C) 2005 CoffeeCup Software */
/****************************************************/
/* - Companion Program For Coffeecup Form Builder - */
/* Visit - http://www.coffeecup.com */
/****************************************************/
/* Constants */
/* Version */ $version = '2.3';
/* Date */ $date = '09/28/05';
/* Error Level */ error_reporting(E_ALL & ~E_NOTICE);
/* Text File */ $saveFile = '[FILENAME]';

//...... Added UTF-8 support

//Config file must be in the same directory as this file
//and have the same first part of the name. i.e. myform.inc.php
list($formName,$ext) = split('\.',basename($_SERVER['PHP_SELF']),2);
if (file_exists($formName.".inc.php"))
{
include($formName.".inc.php");
}

//XML file must be in the same directory as this file
$debug = (isset($_REQUEST['debug'])) ? $_REQUEST['debug'] : $debug;
if ($debug) error_reporting(E_ALL);

//...... Display debugging information
if ($debug)
{
switch($debug)
{
case 'info' :
phpinfo();
exit();
break;

case 'version' :
err("Current MailForm version: <b>".$version."</b><br>Current PHP version: <b>".phpversion()."</b><br> Current Revision Date: <b>$date</b>");
break;
}
}


$date=date("l, F dS, Y \a\\t g:i a");
$server=$_SERVER['SERVER_NAME'];

$msg="Here is the information submitted to $formName from $_SERVER[REMOTE_ADDR] on $date\r\n\r\n------------------------\r\n";

//...... Make sure we keep the variables
$subject = $_REQUEST['subject'];
$thankyoupage = $_REQUEST['thankyoupage'];
$xmlFile = $_REQUEST['xmlfile'];
$unreg = $_REQUEST['uR'];
$email = $_REQUEST['eM'];

if (file_exists($xmlFile))
{
$fd = fopen(basename($xmlFile),'r');
while(!feof($fd))
{
$contents .= fgets($fd,1024);
}
fclose($fd);
}
else
{
err("No &lt;xml&gt; data file found<br>Please upload the data xml file ".$_REQUEST['xmlfile']);
}

$file_info = preg_replace("/\r|\n/"," ",$contents);

//...... Includes the form results in your thank you page
$incresults = (preg_match('/<form.*?includeresults="true".*?>/',$file_info));

//...... Sends email of form results to the user
$emailusr = (preg_match('/<form.*?emailuser="true".*?>/',$file_info));

preg_match('/<hidden.*?name="mailto".*?value="(.*?)".*?>/',$file_info,$matches);
$mailto = $matches[1];

preg_match('/<hidden.*?name="mailto2".*?value="(.*?)".*?>/',$file_info,$matches);
$mailto2 = $matches[1];

preg_match('/<hidden.*?name="thankyoumessage".*?value="(.*?)".*?>/',$file_info,$matches2);
$thanksMsg = unhtmlentities($matches2[1]);


preg_match('/<form.*?bkcolor2="(.*?)".*?>/',$file_info,$matches3);
$backgroundclr = $matches3[1];

preg_match('/<form.*?fontcolor2="(.*?)".*?>/',$file_info,$matches4);
$fontclr = $matches4[1];

preg_match('/<form.*?autoresponse="(.*?)".*?>/',$file_info,$matches5);
$autoresponse = $matches5[1];

if(!$thanksMsg)
{
$thanksMsg="Thank you for your form submission!";
}

if(!$subject)
{
$subject="Form Submission";
}


//...... Reversing array elements so they appear in correct form order
$_REQVARS = array_merge($_POST,$_GET);

//...... Delete them from the request array, we won't need
//...... to send these in the actual email.
unset($_REQVARS['thankyoupage']);
unset($_REQVARS['subject']);
unset($_REQVARS['mailto']);
unset($_REQVARS['mailto2']);
unset($_REQVARS['xmlfile']);
unset($_REQVARS['thankyoumessage']);
unset($_REQVARS['uR']);
unset($_REQVARS['eM']);


$addtoThank.="<span><p align=\"center\">Below is the information you submitted:</br></br></p><p align=\"center\">";
$txtmsg=$formName.'|'.date("Y-m-d H:i:s").'|'.$_SERVER['REMOTE_ADDR'].'|';

$_REQVARS=array_reverse($_REQVARS);

foreach($_REQVARS as $key=>$value)
{
$msg .= "$key: ".stripslashes($value)."\r\n\r\n";
$addtoThank.="$key: ".stripslashes($value)."<br/>";
$txtmsg .= "$key: ".stripslashes($value)."|";
}

$addtoThank.="</p></span>";
$addtoThank=str_replace("_"," ",$addtoThank);

//...... Write to the text file here
if ($saveFile != '[FILENAME]')
{
$fd = fopen($saveFile,"a+");
ccfputcsv($fd, $txtmsg);
fclose($fd);
}

if($unreg == 'true')
{
$unregMsg="<div align=\"center\"><font size=\"1\" face=\"Arial\">Created with CoffeeCup Form Builder <a href=\"http://www.coffeecup.com/\" target=\"_blank\" title=\"CoffeeCup Form Builder\">Download It Here</a></font></div>";
$msg .= "------------------------\r\n\r\nThis Form was sent to you using CoffeeCup Form Builder.\r\nPlease tell a friend about us: http://www.coffeecup.com/form-builder/\r\n";
}
else
{
$unregMsg = '';
}

//...... Why are we converting underscores to spaces?
$newMsg=str_replace("_"," ",$msg) . $autoresponse;

//...... Construct a proper mime/UTF-8 for extended ASCII, and internationalization
$headers = "MIME-Version: 1.0\r\n" . "Content-type: text/plain; charset=UTF-8\r\n\r\n";

//...... If they specify "email" in their form, it will set the reply-to field.
if($email)
{
$sentMail = mail($mailto,$subject,$newMsg,"Reply-To: $email\r\nFrom: $email\r\n$headers");
if ($mailto2 != "")
{
$sentMail2 = mail($mailto2,$subject,$newMsg,"Reply-To: $email\r\nFrom: $email\r\n$headers");
}

//...... MAIL TO USER
if($emailusr)
{
mail($email,$subject,$newMsg,"Reply-To: $mailto\r\n$headers");
if ($mailto2 != "")
{
mail($email,$subject,$newMsg,"Reply-To: $mailto2\r\n$headers");
}
}
}
//...... Send email as regular web server user
else
{
$sentMail = mail($mailto,$subject,$newMsg,$headers);
if ($mailto2 != "")
{
$sentMail2 = mail($mailto2,$subject,$newMsg,$headers);
}
}

if (!$sentMail) err("Cannot send email!");

if(!$incresults)
{
$addtoThank="";
}

if($thankyoupage)
{
header("Location: $thankyoupage");
}
else
{
print <<<__EOT__
<html>

<head>
<title>Form Submitted</title>
<style type="text/css">
<!--
body {
background-color:$backgroundclr;
}
#message {
width:720px;
margin:9px auto;
text-align:center;
font:bold 14px 'Trebuchet MS',arial,helvetica,sans-serif;
color:$fontclr;
}
#message span {
font-weight:normal;
}
//-->
</style>
</head>

<body bgcolor="$background-color">
<center>
<div id="message"><div>$thanksMsg</div>
<br /><br />
$addtoThank
<br /><br />
$unregMsg
</center>
</body>

</html>
__EOT__;

}

function err($string)
{
global $version;
echo("<h2 style=\"font:normal 20px 'Trebuchet MS',arial\">$string</h2>");
echo("<h2 style=\"font:normal 12px 'Trebuchet MX',arial\">Either sendmail or smtp is not properly configured on your system.<br />Please contact your hosting provider to correct this problem.<!-- $version --></h2>");
exit();
}

function ccfputcsv($handle, $mymsg)
{
fputs($handle, $mymsg."\n");//stripslashes(substr($str, 0, -1))

return strlen($mymsg);
}

function unhtmlentities($string)
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}


?>

That replaces the entire php file.
SAVE a backup before using this...
This is untested, and I just did my best to copy the path of the mailto variable with the mailto2 variable. I think it should work.
I'm not sure about the form. the php seems to look for a hidden field in the xml form or something, but I did just copy the line for the mailto var.
BE SURE that you send mailto2 exactly the same way as mailto, except for the name.
I also included if statements so that it doesn't send an email if mailto2 was blank. But it will if it was not blank.

Hope this helps.

djr33
10-02-2006, 06:48 AM
(In response to a PM informing me that it didn't work...)

Turns out I missed something.
the pregmatch() function was saving it into an array... $matchesN where N increased with each repitition. I forgot to do that, so no wonder you're getting really weird result.

Here's the fixed code:
<?php
/****************************************************/
/* CoffeeCup Software Form to Mail program */
/* (C) 2005 CoffeeCup Software */
/****************************************************/
/* - Companion Program For Coffeecup Form Builder - */
/* Visit - http://www.coffeecup.com */
/****************************************************/
/* Constants */
/* Version */ $version = '2.3';
/* Date */ $date = '09/28/05';
/* Error Level */ error_reporting(E_ALL & ~E_NOTICE);
/* Text File */ $saveFile = '[FILENAME]';

//...... Added UTF-8 support

//Config file must be in the same directory as this file
//and have the same first part of the name. i.e. myform.inc.php
list($formName,$ext) = split('\.',basename($_SERVER['PHP_SELF']),2);
if (file_exists($formName.".inc.php"))
{
include($formName.".inc.php");
}

//XML file must be in the same directory as this file
$debug = (isset($_REQUEST['debug'])) ? $_REQUEST['debug'] : $debug;
if ($debug) error_reporting(E_ALL);

//...... Display debugging information
if ($debug)
{
switch($debug)
{
case 'info' :
phpinfo();
exit();
break;

case 'version' :
err("Current MailForm version: <b>".$version."</b><br>Current PHP version: <b>".phpversion()."</b><br> Current Revision Date: <b>$date</b>");
break;
}
}


$date=date("l, F dS, Y \a\\t g:i a");
$server=$_SERVER['SERVER_NAME'];

$msg="Here is the information submitted to $formName from $_SERVER[REMOTE_ADDR] on $date\r\n\r\n------------------------\r\n";

//...... Make sure we keep the variables
$subject = $_REQUEST['subject'];
$thankyoupage = $_REQUEST['thankyoupage'];
$xmlFile = $_REQUEST['xmlfile'];
$unreg = $_REQUEST['uR'];
$email = $_REQUEST['eM'];

if (file_exists($xmlFile))
{
$fd = fopen(basename($xmlFile),'r');
while(!feof($fd))
{
$contents .= fgets($fd,1024);
}
fclose($fd);
}
else
{
err("No &lt;xml&gt; data file found<br>Please upload the data xml file ".$_REQUEST['xmlfile']);
}

$file_info = preg_replace("/\r|\n/"," ",$contents);

//...... Includes the form results in your thank you page
$incresults = (preg_match('/<form.*?includeresults="true".*?>/',$file_info));

//...... Sends email of form results to the user
$emailusr = (preg_match('/<form.*?emailuser="true".*?>/',$file_info));

preg_match('/<hidden.*?name="mailto".*?value="(.*?)".*?>/',$file_info,$matches);
$mailto = $matches[1];

preg_match('/<hidden.*?name="mailto2".*?value="(.*?)".*?>/',$file_info,$matches2);
$mailto2 = $matches2[1];

preg_match('/<hidden.*?name="thankyoumessage".*?value="(.*?)".*?>/',$file_info,$matches3);
$thanksMsg = unhtmlentities($matches3[1]);


preg_match('/<form.*?bkcolor2="(.*?)".*?>/',$file_info,$matches4);
$backgroundclr = $matches4[1];

preg_match('/<form.*?fontcolor2="(.*?)".*?>/',$file_info,$matches5);
$fontclr = $matches5[1];

preg_match('/<form.*?autoresponse="(.*?)".*?>/',$file_info,$matches6);
$autoresponse = $matches6[1];

if(!$thanksMsg)
{
$thanksMsg="Thank you for your form submission!";
}

if(!$subject)
{
$subject="Form Submission";
}


//...... Reversing array elements so they appear in correct form order
$_REQVARS = array_merge($_POST,$_GET);

//...... Delete them from the request array, we won't need
//...... to send these in the actual email.
unset($_REQVARS['thankyoupage']);
unset($_REQVARS['subject']);
unset($_REQVARS['mailto']);
unset($_REQVARS['mailto2']);
unset($_REQVARS['xmlfile']);
unset($_REQVARS['thankyoumessage']);
unset($_REQVARS['uR']);
unset($_REQVARS['eM']);


$addtoThank.="<span><p align=\"center\">Below is the information you submitted:</br></br></p><p align=\"center\">";
$txtmsg=$formName.'|'.date("Y-m-d H:i:s").'|'.$_SERVER['REMOTE_ADDR'].'|';

$_REQVARS=array_reverse($_REQVARS);

foreach($_REQVARS as $key=>$value)
{
$msg .= "$key: ".stripslashes($value)."\r\n\r\n";
$addtoThank.="$key: ".stripslashes($value)."<br/>";
$txtmsg .= "$key: ".stripslashes($value)."|";
}

$addtoThank.="</p></span>";
$addtoThank=str_replace("_"," ",$addtoThank);

//...... Write to the text file here
if ($saveFile != '[FILENAME]')
{
$fd = fopen($saveFile,"a+");
ccfputcsv($fd, $txtmsg);
fclose($fd);
}

if($unreg == 'true')
{
$unregMsg="<div align=\"center\"><font size=\"1\" face=\"Arial\">Created with CoffeeCup Form Builder <a href=\"http://www.coffeecup.com/\" target=\"_blank\" title=\"CoffeeCup Form Builder\">Download It Here</a></font></div>";
$msg .= "------------------------\r\n\r\nThis Form was sent to you using CoffeeCup Form Builder.\r\nPlease tell a friend about us: http://www.coffeecup.com/form-builder/\r\n";
}
else
{
$unregMsg = '';
}

//...... Why are we converting underscores to spaces?
$newMsg=str_replace("_"," ",$msg) . $autoresponse;

//...... Construct a proper mime/UTF-8 for extended ASCII, and internationalization
$headers = "MIME-Version: 1.0\r\n" . "Content-type: text/plain; charset=UTF-8\r\n\r\n";

//...... If they specify "email" in their form, it will set the reply-to field.
if($email)
{
$sentMail = mail($mailto,$subject,$newMsg,"Reply-To: $email\r\nFrom: $email\r\n$headers");
if ($mailto2 != "")
{
$sentMail2 = mail($mailto2,$subject,$newMsg,"Reply-To: $email\r\nFrom: $email\r\n$headers");
}

//...... MAIL TO USER
if($emailusr)
{
mail($email,$subject,$newMsg,"Reply-To: $mailto\r\n$headers");
if ($mailto2 != "")
{
mail($email,$subject,$newMsg,"Reply-To: $mailto2\r\n$headers");
}
}
}
//...... Send email as regular web server user
else
{
$sentMail = mail($mailto,$subject,$newMsg,$headers);
if ($mailto2 != "")
{
$sentMail2 = mail($mailto2,$subject,$newMsg,$headers);
}
}

if (!$sentMail) err("Cannot send email!");

if(!$incresults)
{
$addtoThank="";
}

if($thankyoupage)
{
header("Location: $thankyoupage");
}
else
{
print <<<__EOT__
<html>

<head>
<title>Form Submitted</title>
<style type="text/css">
<!--
body {
background-color:$backgroundclr;
}
#message {
width:720px;
margin:9px auto;
text-align:center;
font:bold 14px 'Trebuchet MS',arial,helvetica,sans-serif;
color:$fontclr;
}
#message span {
font-weight:normal;
}
//-->
</style>
</head>

<body bgcolor="$background-color">
<center>
<div id="message"><div>$thanksMsg</div>
<br /><br />
$addtoThank
<br /><br />
$unregMsg
</center>
</body>

</html>
__EOT__;

}

function err($string)
{
global $version;
echo("<h2 style=\"font:normal 20px 'Trebuchet MS',arial\">$string</h2>");
echo("<h2 style=\"font:normal 12px 'Trebuchet MX',arial\">Either sendmail or smtp is not properly configured on your system.<br />Please contact your hosting provider to correct this problem.<!-- $version --></h2>");
exit();
}

function ccfputcsv($handle, $mymsg)
{
fputs($handle, $mymsg."\n");//stripslashes(substr($str, 0, -1))

return strlen($mymsg);
}

function unhtmlentities($string)
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}


?>
That work?

Cheng
10-02-2006, 07:00 AM
Hi djr33.

I'm just trying it again right now and let you know in a minute if it's working or not.

Cheng

Cheng
10-02-2006, 07:14 AM
Hi djr33.

Very nice.
It's working just fine now.
You been asking what I need it for.
It's just to have a check on something for a while to see if I'm cheated or not.
I also could do this another way by just configuring the form that on every submission a text file with the submitted data is saved on the server but I like it better this way.

Your'e the man!

Thanks again very much.

Cheng

djr33
10-02-2006, 08:24 AM
Yep. Glad it worked.