Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-12-2007, 09:10 PM PHP mailForm
Banned

Posts: 2,898
Location: Canada
Trades: 0
I need to teach mailForm to use Russian charset=windows-1251

Here is the script

<?php

//----- Start Config -----\\

//enter the path to sendmail
$mail_path = "/usr/sbin/sendmail";

//Recipient should be selected from a list, true or false
$listofrecipients = "false";

//sub variable (only edit if above value is set to false)
//enter the email address you wish emails to be sent to
$mail_to = "****@*******.com";

//sub variable (only edit if above value is set to true)
//define list of recipients the user can chose from. Name & Email address should be seperated by ><
$recipientslist = array("Name 1 >< name1@yourdomain.com", "Name 2 >< name2@yourdomain.com", "Name 3 >< name3@yourdomain.com");


//Subject should be selected from a list, true or false
$listofsubjects = "false";

//sub variable (only edit if above value is set to true)
//define list of subjects the user can chose from
$subjects = array("Info Request", "Members", "Feedback", "Webmaster", "Other");

//use security code feature, true or false
$usesecuritycode = "true";

//use time limit feature, true or false
$usetimelimit = "true";

//sub variable (only edit if above value is set to true)
//set time delay if using time limit feature
$delay = "30";

//redirect to another page after successful submission, true or false
$redirectonsuccess = "false";

//sub variable (only edit if above value is set to true)
//set address of page to redirect to after successful submission, can be relative
$redirecturl = "http://www.oldfashionbluesproject.com/";

//allow user to get a copy of the message sent to them, true or false
$copyme = "false";

//store submissions in a database, true or false
$store = "false";

//sub variables (only edit if above value is set to true
//MySQL Host
$host = "localhost";
//MySQL User
$user = "user";
//MySQL Pass
$pass = "pass";
//MySQL Database Name
$dbname = "database";
//Table Name
$tablename = "ContactFormLog";
//Date Format, see http://www.php.net/date
$dateformat = "d/m/Y H:i:s";

//user has to preview before can submit, true or false
$preview = "true";

//remember user's name and e-mail, true or false
$rememberdetails = "false";

//sub variables (only edit if above value is set to true
//Days to remember details for
$rememberdays = "7";

//----- End Config -----\\

//----- Start Set PHP Variables -----\\
ini_set("sendmail_path", $mail_path);
ini_set("magic_quotes_gpc", 1);
//----- End Set PHP Variables -----\\

//----- Start Functions -----\\

//function to check email format
function check_email($str)
{
if(ereg("^.+@.+\\..+$", $str))
return 1;
else
return 0;
}

//function to get submitted values
function get_values($slashes,$decode)
{
global $userName;
global $userEmail;
global $userSubject;
global $userMessage;
global $userCopyMe;
global $userEmailTo;
global $rememberdetails;

$userName = htmlentities(strip_tags($_POST['userName']));
$userEmail = htmlentities(strip_tags($_POST['userEmail']));
$userSubject = htmlentities(strip_tags($_POST['userSubject']));
$userMessage = htmlentities(strip_tags($_POST['userMessage']));
$userCopyMe = htmlentities(strip_tags($_POST['userCopyMe']));
$userEmailTo = htmlentities(strip_tags($_POST['userEmailTo']));

if ($slashes == "1") {

$userName = stripslashes($userName);
$userEmail = stripslashes($userEmail);
$userSubject = stripslashes($userSubject);
$userMessage = stripslashes($userMessage);
$userCopyMe = stripslashes($userCopyMe);
$userEmailTo = stripslashes($userEmailTo);

}

if ($decode == "1") {

$userName = html_entity_decode($userName);
$userEmail = html_entity_decode($userEmail);
$userSubject = html_entity_decode($userSubject);
$userMessage = html_entity_decode($userMessage);
$userCopyMe = html_entity_decode($userCopyMe);
$userEmailTo = html_entity_decode($userEmailTo);

}

}

//function to clear submitted values
function clear_values()
{
global $userName;
global $userEmail;
global $userSubject;
global $userMessage;
global $userCopyMe;
global $userEmailTo;
global $rememberdetails;

if ($rememberdetails != "true") {
$userName = "";
$userEmail = "";
}
$userSubject = "";
$userMessage = "";
$userCopyMe = "";
$userEmailTo = "";
}

//function to display message
function display_messages()
{
global $message;
global $messagenoterror;

$y = "0";
if (!empty($message) && $messagenoterror != "1") {
echo "The following errors were encountered when trying to process
your message:<br />";
}
while ($y < 10) {
if (!empty($message[$y])) {
if ($messagenoterror != "1") {
echo " - ";
}
echo $message[$y]."<br />";
}
$y++;
}
}

//----- End Functions -----\\

//----- Start Set Variables -----\\
$mail_subject = $_POST['userSubject'];
$submittime = $_SESSION['submittime'];
$currenttime = time();
$allowedtime = $currenttime - $delay;
$timeleft = $submittime - $allowedtime;
$p = "0";
get_values(1,1);
$EmailContent = "Name : ".$userName."\n"."Email : ".$userEmail."\n"."Subject : ".$userSubject."\n"."Message : \n".$userMessage."\n\n"."User IP : ".$_SERVER["REMOTE_ADDR"];
//----- End Set Variables -----\\

//check if form submitted
if ($_POST){

//----- Start Error Checking -----\\

//check to see if fields already been checked
if ($_POST['previewdone'] != "1") {

//check if all fields filled in
if (!$_POST['userName'] || !$_POST['userEmail'] || !$_POST['userSubject'] || !$_POST['userMessage']){
$message[$p] = "All required fields not filled in.";
$p++;
get_values(1,0);
$notcomplete = "1";
}

//check if email is in valid format
if(check_email($_POST['userEmail']) == "0" && $_POST['userEmail']){
$message[$p] = "Invalid e-mail address.";
$p++;
get_values(1,0);
}

//check if security code is correct
if($_POST['userSecurityCode'] != base64_decode($_POST['SecurityCode']) && $usesecuritycode == "true" && $notcomplete != "1"){
$message[$p] = "Wrong security code";
$p++;
get_values(1,0);
}

//check that x seconds has passed
if($submittime > $allowedtime && $usetimelimit == "true"){
$message[$p] = "You are trying to send messages too often, please try again after ".$timeleft." seconds";
$p++;
get_values(1,0);
}

}

//----- End Error Checking -----\\

//----- Start Set Cookies ------\\

if ($rememberdetails == "true") {
$cookietime = time()+60*60*24*$rememberdays;
//set cookie to remember userid for x days
setcookie("userName", $_POST['userName'], $cookietime, "/");
//set cookie to remember password for x days
setcookie("userEmail", $_POST['userEmail'], $cookietime, "/");
}

//----- End Set Cookies ------\\

//----- Start Final Check & Process Form ------\\

if ($preview == "true" && $_POST['previewdone'] == "1") {
$continue = "1";
} elseif ($preview == "true" && $_POST['previewdone'] != "1") {
$continue = "0";
} else {
$continue = "1";
}

//check to see whether there are any errors, if no then continue
if (empty($message) && $continue == "1" && empty($_POST['edit'])){

//check to see whether the user can pick the recipitent, if yes get recepitent chosen
if ($listofrecipients == "true") {
$explodedresult = explode(" >< ", $recipientslist[$_POST['userEmailTo']]);
$mail_to = $explodedresult[1];
}

//Check to see if mail sent correctly
get_values(1,0);
if(mail($mail_to,$mail_subject,$EmailContent,"From :".$userName." <".$userEmail.">")){

//check to see if user wants a copy of the message, if yes send them one
if ($_POST['userCopyMe'] == "1"){
mail($_POST['userEmail'],"Copy of sent message: ".$mail_subject,$EmailContent,"From:".$userNam e." <".$userEmail.">");
}

//check to see if user wants to store submissions
if ($store == "true") {
//connect to db
$connect = @mysql_connect($host,$user,$pass);
//select db
$selectdb = @mysql_select_db($dbname);
//get variables
get_values(1,1);
$userAgent = $_SERVER["HTTP_USER_AGENT"];
$userIP = $_SERVER["REMOTE_ADDR"];
$userTime = date($dateformat);
//insert data
$sql = "INSERT INTO `$tablename` (`ID`, `userName`, `userEmail`, `userSubject`, `userMessage`, `userCopyMe`, `userEmailTo`, `userAgent`, `userIP`, `userTime`) VALUES ('', '$userName', '$userEmail', '$userSubject', '$userMessage', '$userCopyMe', '$userEmailTo', '$userAgent', '$userIP', '$userTime')";
$result = @mysql_query($sql);
}

//tell user message sent successfully
$message[0] = "Thank you, your message has been sent.";
$messagenoterror = "1";

//clear form values
clear_values();

//store submit time for use with time limit feature
$_SESSION['submittime'] = time();

//check to see if user should be redirected
if ($redirectonsuccess == "true") {
?>
<script type="text/javascript">
<!--
window.location.href = "<?php echo $redirecturl; ?>";
-->
</script>
<?php
}

//if error provide link
}else{
//provide link to user to send using their default email
$message[0] = "There was an error. Please click <a href=\"mailto:".$mail_to."?subject=".$_POST['userSubject']."&amp;body=".$_POST['userMessage']."\">here</a> to send your message via your default e-mail program.";
$messagenoterror = "1";
get_values(1,0);
}

$formsent = "1";

}

} else {

if ($rememberdetails == "true") {
$userName = $_COOKIE['userName'];
$userEmail = $_COOKIE['userEmail'];
}

}

//----- End Final Check & Process Form ------\\
?> <!-- Start Output --> <?php
if ($preview == "true" && $_POST['previewfirst'] == "1" && $formsent != "1" && empty($message) && empty($_POST['edit'])) {
get_values(1,0);
?> <!-- Start Preview -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100" class="table-text">
<tr align="CENTER" valign="top" class="table-text">
<td>
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
<table width="100%" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#8E2424" style="border-collapse: collapse" class="table-text">
<tr bgcolor="#8E2424">
<td height="12" colspan="2"></td>
</tr>
<tr>
<td height="25" width="174">Names : </td>
<td height="25" width="420"><?php echo $userName; ?>
<input type="hidden" name="userName" value="<?php echo $userName; ?>" />
</td>
</tr>
<tr>
<td height="25" width="174">Email : </td>
<td height="25" width="420"><?php echo $userEmail; ?>
<input type="hidden" name="userEmail" value="<?php echo $userEmail; ?>" />
</td>
</tr>
<tr>
<td height="25" width="174">Subject : </td>
<td height="25" width="420"><?php if ($listofsubjects == "true") { ?>
<?php echo $userSubject; ?> <?php } else { ?>
<?php
$i = "0";
while ($i < count($subjects)){
?> <?php if ($userSubject == $subjects[$i]) { echo $subjects[$i]; } ?> <?php $i++; }?>
<?php } ?>
<input type="hidden" name="userSubject" value="<?php echo $userSubject; ?>" />
</td>
</tr>
<tr>
<td height="25" colspan="2">Message : <br />
<?php echo nl2br($userMessage); ?>
<input type="hidden" name="userMessage" value="<?php echo $userMessage; ?>" />
</td>
</tr>
<tr align="center" bgcolor="#8E2424">
<td height="25" colspan="2">
<input type="submit" name="edit" value="Edit" />
<input type="submit" name="submit" value="Send" />
</td>
</tr>
</table>
<!-- Start Preview Done Field -->
<input type="hidden" name="previewdone" value="1" />
<!-- End Preview Done Field -->
</form>
</td>
</tr>
</table>
<!----- End Preview -----> <br />
<?php
} else {
?> <?php
//display any messages
display_messages();
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100" class="warning">
<tr align="CENTER" valign="top">
<td>
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
<table width="100%" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#8E2424" style="border-collapse: collapse" class="table-text">
<tr>
<td height="12" colspan="2" bgcolor="#8E2424">&nbsp;&nbsp;&nbsp;&nbsp;Please
use English</td>
</tr>
<tr>
<td height="25" width="23%"> <!-- Start Name Field-->&nbsp;
Name : </td>
<td height="25" width="77%">
<input type="text" name="userName" maxlength="30" size="40" style='border: 1 solid rgb(50,50,50);' value="<?php echo $userName; ?>" />
<!-- End Name Field--></td>
</tr>
<tr>
<td height="25" width="23%"> <!-- Start E-mail Field-->&nbsp;
E-mail : </td>
<td height="25" width="77%">
<input type="text" name="userEmail" maxlength="30" size="40" style='border: 1 solid rgb(50,50,50);' value="<?php echo $userEmail; ?>" />
<!-- End E-mail Field--></td>
</tr>
<tr>
<td height="25" width="23%"> <!-- Start Subject Field-->&nbsp;
Subject : </td>
<td height="25" width="77%"><?php if ($listofsubjects == "true") { ?>
<input type="text" name="userSubject" value="<?php echo $userSubject; ?>" />
<?php } else { ?>
<select name="userSubject">
<?php
$i = "0";
while ($i < count($subjects)){
?>
<option value="<?php echo $subjects[$i]; ?>" <?php if ($userSubject == $subjects[$i]) { echo "selected=\"selected\""; }?>><?php echo $subjects[$i]; ?></option>
<?php $i++; }?>
</select>
<?php } ?> <!-- End Subject Field--></td>
</tr>
<tr align="left">
<td height="25" colspan="2">&nbsp; <b><font size="1" face="Verdana" />Message
:</font></b> <br />
&nbsp; &nbsp;
<textarea name="userMessage" rows="8" cols="50" style='border: 1 solid rgb(50,50,50); background-color: #CE791C;'><?php echo $userMessage; ?></textarea>
<!-- End Message Field--></td>
</tr>
<tr>
<td height="25" colspan="2"> <!-- Start Security Code Field-->
<?php
//check to see if security code feature is on
if ($usesecuritycode == "true") {
$randcode = mt_rand(100000, 999999);
$randcodesec = base64_encode($randcode);
?> <b><font size="1" face="Verdana">&nbsp; Type the code you see
on the image below </font></b><br />
&nbsp;
<input type="text" name="userSecurityCode" maxlength="6" size="8" style='border: 1 solid rgb(50,50,50);'>
<input type="hidden" name="SecurityCode" value="<?php echo $randcodesec; ?>" />
<br />
&nbsp; <img src="gd.php?randcode=<?php echo $randcodesec; ?>" alt="Security Code" />
<?php } ?> <!-- End Security Code Field--></td>
</tr>
<tr align="center">
<td height="25" colspan="2" bgcolor="#8E2424"><!-- Start Submit Button-->
<input type="submit" name="submit" value="<?php if ($preview == "true") { echo "Preview Before Send"; } else { echo "Send"; } ?>" />
<!-- End Submit Button--></td>
</tr>
<!-- Start Preview First Field --> <?php if ($preview == "true") {?>
<input type="hidden" name="previewfirst" value="1" />
<?php } ?> <!-- End Preview First Field -->
</table>
</form>
</td>
</tr>
</table>
<br />
<?php
}
ob_end_flush();
?> <!-- End Output -->


fastreplies

Last edited by fastreplies; 12-12-2007 at 09:17 PM..
fastreplies is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-16-2007, 02:45 PM Re: PHP mailForm
Banned

Posts: 2,898
Location: Canada
Trades: 0
Are you guys telling me that 50 people who viewed this post
have no idea how I can solve the issue?

You can do better than that.
Can you?


fastreplies
fastreplies is offline
Reply With Quote
View Public Profile
 
Old 12-17-2007, 06:05 AM Re: PHP mailForm
Experienced Talker

Posts: 30
Trades: 0
explain the issue then
klaroen is offline
Reply With Quote
View Public Profile
 
Old 12-17-2007, 03:18 PM Re: PHP mailForm
Banned

Posts: 2,898
Location: Canada
Trades: 0
Quote:
Originally Posted by klaroen View Post
explain the issue then
Ok,

I builded this site for Russian Band and because 99.99% of mailForm users
will be using Cyrillic, it must understand/decode Cyrillic fonts.

using
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
or any other META tag wouldn't do any good


fastreplies
fastreplies is offline
Reply With Quote
View Public Profile
 
Old 12-17-2007, 07:33 PM Re: PHP mailForm
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Would this work (?):

PHP Code:
<form action="<?php echo $_SERVER["REQUEST_URI"]; ?>" accept-charset="windows-1251" enctype="application/x-www-form-urlencoded" method="post">
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 12-18-2007, 01:19 PM Re: PHP mailForm
Banned

Posts: 2,898
Location: Canada
Trades: 0
mgraphic, thanks for your suggestion but …
the problem as I can see it come from confirmation part of that form.

There are no problems to type Russian into the fields, the problem is coming
when script take info and move it to the next step – confirmation part.
At that point it changes Cyrillic type into something else.



fastreplies
fastreplies is offline
Reply With Quote
View Public Profile
 
Old 12-18-2007, 07:40 PM Re: PHP mailForm
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
What about passing a http header to set the charset in your pages?

PHP Code:
header('Content-Type: text/html; charset=windows-1251'); 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 12-18-2007, 09:55 PM Re: PHP mailForm
Banned

Posts: 2,898
Location: Canada
Trades: 0
I started with header but after it wouldn't work I decided to ask for help






fastreplies
fastreplies is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP mailForm
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44381 seconds with 12 queries