Log in

View Full Version : PHP info form.



benh
12-10-2007, 05:07 PM
I seem to having an issue with a form i made. I can't get it to read properly on my localhost server. I have everything installed properly but i think there is an issue with my code.
form.php


<?php include_once( "form.lib.php" ); ?>
<html>
<head>
<!-- Begin: Form -->



<?php
if( !$isHideForm ):
global $sErr ;
if( $sErr ) print "<br><a name='error'></a><center><font class='form_error' >$sErr</font></center><br>";

$starColor = $sErr ? "#ff0000" : "#000000";
$style=" class='form_text' ";
?>

<form name="frmFormMail" action="<?php print PHP_SELF ?>" method='post' enctype='multipart/form-data'>
<input type='hidden' name='formmail_submit' value='Y'>
<input type='hidden' name='esh_formmail_subject' value="Appointment Leads">
<input type='hidden' name='esh_formmail_return_subject' value="Appointment Set Thank You!">
<input type='hidden' name='esh_formmail_return_msg' value="You appointment has been set and a representative
will be sent to the address given for your free
estimate.
Thank you
CC Carpet

Bes Prices Everyday!">

<table cellspacing='16' cellpadding='0' border='0' >
<tr>
<td class="form_field" valign='top' align='right'>First Name </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<input type="text" name="First_Name" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "First_Name" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Last Name </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<input type="text" name="Last_Name" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Last_Name" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Spouse's_First </td><td width='10' aligh='right' valign='top'></td>
<td class="form_text">
<input type="text" name="Spouse_s_First" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Spouse_s_First" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Spouse's_Last </td><td width='10' aligh='right' valign='top'></td>
<td class="form_text">
<input type="text" name="Spouse_s_Last" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Spouse_s_Last" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Street Address </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<input type="text" name="Street_Address" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Street_Address" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>City </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<input type="text" name="City" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "City" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>State </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<input type="text" name="State" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "State" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Zip </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<input type="text" name="Zip" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Zip" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Main Phone </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<input type="text" name="Main_Phone" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Main_Phone" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Secondary Phone </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<input type="text" name="Secondary_Phone" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Secondary_Phone" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Email </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<input type="email" name="Email" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Email" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Residential </td><td width='10' aligh='right' valign='top'></td>
<td class="form_text">
<input type="checkbox" name="Checkbox01_Residential" value="<?php formChecked( $HTTP_POST_VARS[ "Checkbox01_Residential" ], "" ); ?>" > <br>

</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Interested In? </td><td width='10' aligh='right' valign='top'></td>
<td class="form_text">
<input type="text" name="Interested_In" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Interested_In" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>How did you hear about us? </td><td width='10' aligh='right' valign='top'></td>
<td class="form_text">
<input type="text" name="How_did_you_hear_about_us" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "How_did_you_hear_about_us" ] ); ?>" class='text_box'>
</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Appointment Date </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<?php
selectList( "Appointment_Date_MM", $HTTP_POST_VARS["Appointment_Date_MM"], 1, 12, "MM", $style ) ;
selectList( "Appointment_Date_DD", $HTTP_POST_VARS["Appointment_Date_DD"], 1, 31, "DD", $style ) ;
selectList( "Appointment_Date_YYYY", $HTTP_POST_VARS["Appointment_Date_YYYY"], date("Y"), date("Y")+3, "YYYY", $style ) ;
?>

</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Appointment Time </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<?php
selectList( "Appointment_Time_HH", $HTTP_POST_VARS["Appointment_Time_HH"], 0, 23, "HH", $style ) ;
selectList( "Appointment_Time_MM", $HTTP_POST_VARS["Appointment_Time_MM"], 0, 59, "MM", $style ) ;
?>

</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Alternate Date </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<?php
selectList( "Alternate_Date_MM", $HTTP_POST_VARS["Alternate_Date_MM"], 1, 12, "MM", $style ) ;
selectList( "Alternate_Date_DD", $HTTP_POST_VARS["Alternate_Date_DD"], 1, 31, "DD", $style ) ;
selectList( "Alternate_Date_YYYY", $HTTP_POST_VARS["Alternate_Date_YYYY"], date("Y"), date("Y")+3, "YYYY", $style ) ;
?>

</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Alternate Time </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
<td class="form_text">
<?php
selectList( "Alternate_Time_HH", $HTTP_POST_VARS["Alternate_Time_HH"], 0, 23, "HH", $style ) ;
selectList( "Alternate_Time_MM", $HTTP_POST_VARS["Alternate_Time_MM"], 0, 59, "MM", $style ) ;
?>

</td>
</tr>

<tr>
<td class="form_field" valign='top' align='right'>Comments? </td><td width='10' aligh='right' valign='top'></td>
<td class="form_text">
<textarea name="Comments" rows=4 cols=25 ><?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Comments" ] ); ?></textarea>

</td>
</tr>


<tr><td colspan=3 align='center'><input type='submit' value='Submit'> &nbsp;&nbsp; <input type='button' value='Cancel' onClick="location.href='/';"></td></tr>
</table>


</form>




<!-- End: -->



<?php
if( $sErr ) print "<script language='javascript' type='text/javascript'>location.href='#error';</script>";;;

else: //!$isHideForm
print( "<br><br><hr><center><b>Your form has been sent. Thank you.</b><br><br><input type='button' value='Home' onclick=\"location.href='/';\"></center><br><br>" );
endif; //!$isHideForm
?>

benh
12-10-2007, 05:10 PM
form.lib.php


<?php
error_reporting(E_PARSE);
define("ADMIN_MAIL", "jb@bwp.net");
define("HOST_NAME", $_SERVER['HTTP_HOST']);
define("PHP_SELF", $_SERVER['PHP_SELF']);
define("ERR_MISSING", "Missing required field : ");
define("ERR_EMAIL", "Please enter a valid e-mail address : ");
define("ERR_CREDIT_CARD_NUMBER", "Please check the credit card number : ");
define("ERR_CREDIT_CARD_EXPIRED", "Please check the credit card expiry date : ");
define("ERR_SELECT_UPLOAD", "Please select file : ");// recipient
define('FORM_RECIPIENT', 'appointment@cccarpet.com');
// --- Array of Form Elements ---
$form_mail[] = array( "name" => "First_Name", "text" => "First Name", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Last_Name", "text" => "Last Name", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Spouse<?php $_SESSION[]; ?>_s_First", "text" => "Spouse\'s_First", "type" => "text", "required" => "" ) ;
$form_mail[] = array( "name" => "Spouse_s_Last", "text" => "Spouse\'s_Last", "type" => "text", "required" => "" ) ;
$form_mail[] = array( "name" => "Street_Address", "text" => "Street Address", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "City", "text" => "City", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "State", "text" => "State", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Zip", "text" => "Zip", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Main_Phone", "text" => "Main Phone", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Secondary_Phone", "text" => "Secondary Phone", "type" => "text", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Email", "text" => "Email", "type" => "email", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Residential", "text" => "Residential", "type" => "checkbox", "required" => "" ) ;
$form_mail[] = array( "name" => "Interested_In", "text" => "Interested In?", "type" => "text", "required" => "" ) ;
$form_mail[] = array( "name" => "How_did_you_hear_about_us", "text" => "How did you hear about us?", "type" => "text", "required" => "" ) ;
$form_mail[] = array( "name" => "Appointment_Date", "text" => "Appointment Date", "type" => "date(mm-dd-yyyy)", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Appointment_Time", "text" => "Appointment Time", "type" => "time(hh:mm)", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Alternate_Date", "text" => "Alternate Date", "type" => "date(mm-dd-yyyy)", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Alternate_Time", "text" => "Alternate Time", "type" => "time(hh:mm)", "required" => "Required" ) ;
$form_mail[] = array( "name" => "Comments", "text" => "Comments?", "type" => "textarea", "required" => "" ) ;

benh
12-10-2007, 05:11 PM
form.lib.php
rest


// -- Create new vars for checkPass() & sendFormMail() --
$Residential = array();
$Residential[0]=$HTTP_POST_VARS[ "Checkbox01_Residential"];
$HTTP_POST_VARS[ "Residential" ] = join( "\n", $Residential);

$HTTP_POST_VARS[ "Appointment_Date" ] = ( $HTTP_POST_VARS[ "Appointment_Date_YYYY" ] && $HTTP_POST_VARS[ "Appointment_Date_MM" ] && $HTTP_POST_VARS[ "Appointment_Date_DD" ] )
? $HTTP_POST_VARS[ "Appointment_Date_YYYY" ] . "-" . $HTTP_POST_VARS[ "Appointment_Date_MM" ] . "-" . $HTTP_POST_VARS[ "Appointment_Date_DD" ]
: "" ;
$HTTP_POST_VARS[ "Appointment_Time" ] = ( $HTTP_POST_VARS[ "Appointment_Time_HH" ] && $HTTP_POST_VARS[ "Appointment_Time_MM" ] )
? $HTTP_POST_VARS[ "Appointment_Time_HH" ] . ":" . $HTTP_POST_VARS[ "Appointment_Time_MM" ]
: "" ;
$HTTP_POST_VARS[ "Alternate_Date" ] = ( $HTTP_POST_VARS[ "Alternate_Date_YYYY" ] && $HTTP_POST_VARS[ "Alternate_Date_MM" ] && $HTTP_POST_VARS[ "Alternate_Date_DD" ] )
? $HTTP_POST_VARS[ "Alternate_Date_YYYY" ] . "-" . $HTTP_POST_VARS[ "Alternate_Date_MM" ] . "-" . $HTTP_POST_VARS[ "Alternate_Date_DD" ]
: "" ;
$HTTP_POST_VARS[ "Alternate_Time" ] = ( $HTTP_POST_VARS[ "Alternate_Time_HH" ] && $HTTP_POST_VARS[ "Alternate_Time_MM" ] )
? $HTTP_POST_VARS[ "Alternate_Time_HH" ] . ":" . $HTTP_POST_VARS[ "Alternate_Time_MM" ]
: "" ;



// -- Detech Submit & SendMail --
$isHideForm = false;
if( $HTTP_POST_VARS["formmail_submit"] ){
$sErr = checkPass();
if( ! $sErr ){
sendFormMail( $form_mail, "") ;
$isHideForm = true;

$redirect = "";
if( strlen(trim($redirect)) ):
header( "Location:$redirect" );
exit;
endif;
}
}


?>
<?
// ===============================================
function sendFormMail( $form_mail, $sFileName = "" )
{
global $HTTP_POST_VARS ;

if (ereg('/freeformmaker.com/', HOST_NAME))
{
return;
}
$to = FORM_RECIPIENT;
$from = "NO_REPLY@" . HOST_NAME;
$subject = $HTTP_POST_VARS["esh_formmail_subject"];

// first stage keep it simple:
$sWhatToDo = $sFileName ? "mailandfile" : "" ; //$HTTP_POST_VARS["esh_formmail_mail_and_file"];

//$sFileName = $HTTP_POST_VARS["esh_formmail_save_record_file"];
$cc = $HTTP_POST_VARS["esh_formmail_cc"];
$bcc = $HTTP_POST_VARS["esh_formmail_bcc"];
$charset = $HTTP_POST_VARS["esh_formmail_charset"];

for( $i = 0; $i < count( $form_mail ); $i ++ ){
$value = trim( $HTTP_POST_VARS[ $form_mail[ $i ][ "name" ] ] );
$content .= $form_mail[ $i ][ "text" ] . " \t : " . $value ."\n";
$line .= remove_newline( $value ) . "\t" ;
if( strtolower("Sender's email") == strtolower($form_mail[ $i ][ "type" ]) ) {
//print "Type:[" . $form_mail[ $i ][ "type" ] . "] $value <br>\n";
$from = $value ;
}
};
$content .= "\n\nIP:" . getEnv( "REMOTE_ADDR" );

switch( strtolower($sWhatToDo) ){
case "mailandfile" :
mailAttachments( $to , $subject , $content, $from, $charset, $cc , $bcc ) ;
if( ! appendToFile( $sFileName, $line ) )
mailReport( $content . "\n\nWrite Form Mail to File Fail." );
break;

case "fileonly" :
if( ! appendToFile( $sFileName, $line ) )
mailReport( $content . "\n\nWrite Form Mail to File Fail.", $from );
break;

default :
mailAttachments( $to , $subject , $content, $from, $charset, $cc , $bcc ) ;
}

mailAutoResponse( $from ) ;
}


//------------------------------------------------------------------------------------------
function mailAutoResponse( $to ){
global $HTTP_POST_VARS ;
$subject = $HTTP_POST_VARS["esh_formmail_return_subject"];
$responseMsg = $HTTP_POST_VARS["esh_formmail_return_msg"];
if( $to && $responseMsg )
mail( $to, $subject, $responseMsg, "From: " . FORM_RECIPIENT);
}


//------------------------------------------------------------------------------------------
function mailReport( $content = "", $from = "" ){
mail( ADMIN_MAIL, "Error@" . HOST_NAME . PHP_SELF, $content, "From:$from" );
}

//------------------------------------------------------------------------------------------
function remove_newline( $str = "" ){
$newliner = "<!--esh_newline-->" ; // replace \r\n with $newliner ;
$newtaber = "<!--esh_newtaber-->" ; // replace \t with $newtaber ;
$str = ereg_replace( "\t", $newtaber, $str );
$str = ereg_replace( "\r\n", $newliner, $str );
return ereg_replace( "\n", $newliner, $str );
}

//------------------------------------------------------------------------------------------
function checkPass()
{
global $form_mail ;
global $HTTP_POST_VARS ;
global $HTTP_POST_FILES ;

for( $i = 0; $i < count( $form_mail ); $i ++ ){
$type = strtolower( $form_mail[ $i ][ "type" ] );
$value = trim( $HTTP_POST_VARS[ $form_mail[ $i ][ "name" ] ] );
$required = $form_mail[ $i ][ "required" ] ;
$text = stripslashes( $form_mail[ $i ][ "text" ] );

// simple check the field has something keyed in.
if( !strlen($value) && ( $required == "Required" ) && $type != "attachment" )
return ERR_MISSING . $text ;

// verify the special case
/*if(
( strlen($value) || $type == "attachment" )
&& $required == "Required"
):
*/
switch( $type ){
case strtolower("Sender's Name") :
break;
case strtolower("Generic email"):
//case strtolower("Sender's email"):
case "email":
if( ! formIsEMail($value) ) return ERR_EMAIL . $text ;
break;
case "text" :
break;
case "textarea" :
break;
case "checkbox" :
case "radio" :
break;
case "select" :
break;
case "attachment" :
$upload_file = $HTTP_POST_FILES[ $form_mail[ $i ]["name"] ][ "tmp_name" ] ;
if( ! is_uploaded_file($upload_file) )
return ERR_SELECT_UPLOAD . $text;
break;
case strtolower("Date(MM-DD-YYYY)"):
break;
case strtolower("Date(MM-YYYY)"):
break;
case strtolower("CreditCard(MM-YYYY)"):
if( $value < date("Y-m") ) return ERR_CREDIT_CARD_EXPIRED . $text;
break;
case strtolower("CreditCard#"):
if( !formIsCreditNumber( $value ) ) return ERR_CREDIT_CARD_NUMBER . $text ;
break;
case strtolower("Time(HH:MM:SS)"):
break;
case strtolower("Time(HH:MM)"):
break;
default :
//return $sErrRequired . $form_mail[ $i ][ "text" ];
} // switch
//endif;
} // for

return "" ;
}



//------------------------------------------------------------------------------------------
function formSelected( $var, $val )
{
echo ( $var == $val ) ? "selected" : "";
}


//------------------------------------------------------------------------------------------
function formChecked( $var, $val )
{
echo ( $var == $val ) ? "checked" : "";
}


//------------------------------------------------------------------------------------------
function formIsEMail( $email ){
return ereg( "^(.+)@(.+)\\.(.+)$", $email );
}

benh
12-10-2007, 05:12 PM
//------------------------------------------------------------------------------------------
function selectList( $name, $selectedValue, $start, $end, $prompt = "-Select-", $style = "" )
{
$tab = "\t" ;
print "<select name=\"$name\" $style>\n" ;
print $tab . "<option value=''>$prompt</option>\n" ;
$nLen = strlen( "$end" ) ;
$prefix_zero = str_repeat( "0", $nLen );
for( $i = $start; $i <= $end ; $i ++ ){
$stri = substr( $prefix_zero . $i, strlen($prefix_zero . $i)-$nLen, $nLen );
$selected = ( $stri == $selectedValue ) ? " selected " : "" ;
print $tab . "<option value=\"$stri\" $selected >$stri</option>\n" ;
}
print "</select>\n\n" ;
}


//------------------------------------------------------------------------------------------
// something like CreditCard.pm in perl CPAN
function formIsCreditNumber( $number ) {

$tmp = $number;
$number = preg_replace( "/[^0-9]/", "", $tmp );

if ( preg_match( "/[^\d\s]/", $number ) ) return 0;
if ( strlen($number) < 13 && 0+$number ) return 0;

for ($i = 0; $i < strlen($number) - 1; $i++) {
$weight = substr($number, -1 * ($i + 2), 1) * (2 - ($i % 2));
$sum += (($weight < 10) ? $weight : ($weight - 9));
}

if ( substr($number, -1) == (10 - $sum % 10) % 10 ) return $number;
return $number;
}


// -------------------------- Begin Mail Attachment Functions -----------------------------------------------------------------
function mailAttachments( $to = "" , $subject = "" , $message = "" , $from = "support@lynx.net" , $charset = "iso-8859-1", $cc = "" , $bcc = "" ){
global $HTTP_POST_FILES ;

if( ! strlen( trim( $to ) ) ) return "Missing \"To\" Field." ;

$boundary = "====_My_PHP_Form_Generator_" . md5( uniqid( srand( time() ) ) ) . "====";

// setup mail header infomation
$headers = "From: $from\r\n";
if ($cc) $headers .= "CC: $cc\r\n";
if ($bcc) $headers .= "BCC: $bcc\r\n";
$plainHeaders = $headers ; // for no attachments header
$headers .= "MIME-Version: 1.0\nContent-type: multipart/mixed;\n\tboundary=\"$boundary\"\n";

$txtMsg = "\nThis is a multi-part message in MIME format.\n" .
"\n--$boundary\n" .
"Content-Type: text/plain;\n\tcharset=\"$charset\"\n\n" . $message . "\n";

//create mulitipart attachments boundary
$sError = "" ;
$nFound = 0;
foreach( $HTTP_POST_FILES as $aFile ){
$sFileName = $aFile[ "tmp_name" ] ;
$sFileRealName = $aFile[ "name" ] ;
if( is_file( $sFileName ) ):

if( $fp = fopen( $sFileName, "rb" ) ) :
$sContent = fread( $fp, filesize( $sFileName ) );
$sFName = basename( $sFileRealName ) ;
$sMIME = getMIMEType( $sFName ) ;

$bPlainText = ( $sMIME == "text/plain" ) ;
if( $bPlainText ) :
$encoding = "" ;
else:
$encoding = "Content-Transfer-Encoding: base64\n";
$sContent = chunk_split( base64_encode( $sContent ) );
endif;

$sEncodeBody .= "\n--$boundary\n" .
"Content-Type: $sMIME;\n" .
"\tname=\"$sFName\"\n" .
$encoding .
"Content-Disposition: attachment;\n" .
"\tfilename=\"$sFName\"\n\n" .
$sContent . "\n" ;
$nFound ++;
else:
$sError .= "<br>File $sFileName can not open.\n" ;
endif; // if( $fp = fopen( $sFileName, "rb" ) ) :

else:
$sError .= "<br>File $sFileName doesn't exist.\n" ;
endif; //if( file_exists( $sFileName ) ):
}; // end foreach

$sEncodeBody .= "\n\n--$boundary--" ;
$sSource = $txtMsg . $sEncodeBody ;


$nFound ? mail( $to, $subject, $sSource, $headers )
: mail( $to, $subject, $message, $plainHeaders );

return $sError ;
}

/* ---------------------------------------------------------------------------------------------------
Parameters: $sFileName
Return :
1. "" : no extendsion name, or sFileName is empty
2. string: MIME Type name of array aMimeType's definition.
---------------------------------------------------------------------------------------------------*/
function getMIMEType( $sFileName = "" ) {

$sFileName = strtolower( trim( $sFileName ) );
if( ! strlen( $sFileName ) ) return "";

$aMimeType = array(
"txt" => "text/plain" ,
"pdf" => "application/pdf" ,
"zip" => "application/x-compressed" ,

"html" => "text/html" ,
"htm" => "text/html" ,

"avi" => "video/avi" ,
"mpg" => "video/mpeg " ,
"wav" => "audio/wav" ,

"jpg" => "image/jpeg " ,
"gif" => "image/gif" ,
"tif" => "image/tiff " ,
"png" => "image/x-png" ,
"bmp" => "image/bmp"
);
$aFile = split( "\.", basename( $sFileName ) ) ;
$nDiminson = count( $aFile ) ;
$sExt = $aFile[ $nDiminson - 1 ] ; // get last part: like ".tar.zip", return "zip"

return ( $nDiminson > 1 ) ? $aMimeType[ $sExt ] : "";
}
// End Mail Attachment Functions


//------------------------------------------------------------------------------------------
function appendToFile( $sFileName = "", $line = "" ){
if( !$sFileName || !$line ) return 0;
$hFile = fopen( "$sFileName", "a+w" );
$nBytes = 0;
if( $hFile ){
$nBytes = fputs( $hFile , trim($line)."\r\n" );
fclose( $hFile );
};
return $nBytes ;
}
?>[/