Page 1 of 1

PHP form fields and charset problem

Posted: Sun Jul 05, 2009 4:36 pm
by speed
I have a form on this page http://elitetradesmen.com/Job%20descriptions/101.php everything submits fine apart from one thing. When i receive the email from the submitted form the £ sign which is entered in the quote field always has a  in front of it. Is this something to do with the char set assigned to the feild. Any help which will resolve this annoying problem would be much appreciated.

Code: Select all

<?php
 
ini_set('display_errors', 1);
 
extract($_POST);
 
if (!file_exists("../config.php")) 
 
    {
$host = $_SERVER[HTTP_HOST ];
$path = pathinfo($_SERVER['PHP_SELF']);
$file_path = $path['dirname'];
exit;
    }
    
include "../config.php";
 
if ($sendto_email == "changeme@example.com")
 
    {
exit;
    } 
 
if (!empty($_POST['job_number']))
    {
    $msg = "job_number; $_POST[job_number] ";
    }else{
    $job_number = NULL;
    $info_error .= $lang_nojobnumber . "<br>";
    }
 
if (!empty($_POST['your_business_name']))
    {
    $msg = "your_business_name; $_POST[your_business_name] ";
    }else{
    $your_business_name = NULL;
    $info_error .= $lang_nobusiness . "<br>";
    }
 
if (!empty($_POST['your_start_date']))
    {
    $msg = "your_start_date; $_POST[your_start_date] ";
    }else{
    $your_start_date = NULL;
    $info_error .= $lang_nostartdate . "<br>";
    }
    
if (!empty($_POST['your_completion_date']))
    {
    $msg = "your_completion_date; $_POST[your_completion_date] ";
    }else{
    $your_completion_date = NULL;
    $info_error .= $lang_nocompletiondate . "<br>";
    }
 
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $senders_email))
    {
    $error = "1";
    $info_error .= $lang_invalidemail . "<br>"; 
    }
    
if (!empty($_POST['additional_information']))
    {
    $msg = "additional_information; $_POST[additional_information] ";
    }else{
    $additional_information = NULL;
    $info_error .= $lang_noadditionalinformation . "<br>";
    }   
    
if (empty ($security_code))  
    {
    $error = "1";
    $info_error .= $lang_nocode . "<br>";  
    }
    
if ($terms != "1") 
    {
    $error = "1";
    $info_error .= "Please accept the terms and conditions and try again<br><br>";  
  }
 
elseif ($security_code != $randomness)  
    {
    $error = "1";
    $info_error .= $lang_wrongcode . "<br>";  
    }
    
if ($showlink != "no")
    
    {
    $link = "<br><span style=\"font-size: 10px;\">Powered by <a href=\"http://www.bellonline.co.uk/web-services/free/scripts/php-mailer-script/\" title=\"free PHP mailer script\">BELLonline PHP mailer script</a></span>";
    }
    
if ($error == "1") 
 
    {
    $info_notice = "<span style=\"color: " . $error_colour . "; font-weight: bold;\">" . $lang_error . "</span><br>"; 
    
if (empty ($submit)) 
        {
        $info_error = "";
        $info_notice = $lang_notice;
        }   
 
    function Random() 
        {
        $chars = "ABCDEFGHJKLMNPQRSTUVWZYZ23456789";
        srand((double)microtime()*1000000);
        $i = 0;
        $pass = '' ;
        while ($i <= 4) 
            {
            $num = rand() % 32;
            $tmp = substr($chars, $num, 1);
            $pass = $pass . $tmp;
            $i++; 
            } 
        return $pass; 
        }
    $random_code = Random();
    $mail_message = stripslashes($mail_message);
 
    print "<form name=\"BELLonline_email\" method=\"post\" style=\"margin: 0;\" action=\"\">";
 
    echo "<strong><font color=\"FF0000\">".$info_error."</font></strong>";
    
    ?>
    
    <!--Elitetradesmen form -->
    
<p>To quote for this job please fill in the details below:</p>
    
    <p><BR>            
    <LABEL for="job_number">Job Number: </LABEL>          
                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       
    <label for="your_business_name">Your Business Name: <br />
    <input name="job_number" type="text" id="job_number" value="<?=$job_number;?>" />
    
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
    <input type="text" id="your_business_name" name="your_business_name" value="<?=$your_business_name;?>" />
    <br /></label><BR>      
    <label for="your_start_date">Your Start Date: </label>
                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      
    Your Completion Date:<BR>
    <INPUT type="text" id="your_start_date" name="your_start_date" value="<?=$your_start_date;?>"> 
    <label for="your_completion_date">
    
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        
    <input type="text" id="your_completion_date" name="your_completion_date" value="<?=$your_completion_date;?>"/>
    <br /><br />
    <label for="email">Email:</label><br />
    <input type="text" id="senders_email" name="senders_email" value="<?=$senders_email;?>"/>
    <br /><label for="additional_information">
    
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
    <br /></label>
    Your quote with any additional information:
    <br />
    <textarea name="additional_information" cols="35" rows="5" id="details" name="additional_information"><?=$additional_information;?></textarea>
    <br /><BR>
    <label>
    <input name="terms" type="checkbox" id="terms" value="1" /> Please check the box to confirm you have read and agree to our <a href="../policies.html">Terms and conditions
    </a></label>
    <a href="../policies.html">
    <br/>
    </a><br/>             
             
             <!-- end elite tradesmen form -->
                
    <?
    
    // DO NOT EDIT THE BELOW
    
    print "Please enter the text in the box. (case sensitive): <input name=\"security_code\" type=\"text\" id=\"security_code\" size=\"5\"> 
        &nbsp;&nbsp;&nbsp;&nbsp;<b>$random_code</b><input name=\"randomness\" type=\"hidden\" id=\"randomness\" value=\"$random_code\">
      <p><br />
      <input name=\"submit\" type=\"submit\" id=\"submit\" value=\"$lang_submit\" class=\"mailform_button\">
        </form>";
        
    }
else
    {
    
if ($checkdomain == "yes") 
        {
        $sender_domain = substr($senders_email, (strpos($senders_email, '@')) +1);
        $recipient_domain = substr($sendto_email, (strpos($sendto_email, '@')) +1);
        if ($sender_domain == $recipient_domain)
            {
            print "Sorry, you cannot send messages from this domain ($sender_domain)";
            exit;
            }       
        }
            
    $info_notice = $lang_sent;
    
    /* THE FOLLOWING CODE FORMATS THE EMAIL CONTENT */
    //We create a mail_message field with any POSTED FORM ELEMENT.
    //To access such an element, we use the name of any form input with a 
    //$ symbol before it, so for example to get their name, I use senders_name
    
    $mail_subject = "Email enquiry from Elite Tradesmen website";
    $mail_message = "***<b>ELITE TRADESMEN WEBSITE - QUOTE FOR WORK</b>***<br/><br/>"
    . $mail_message .
    "Job Number: ". $job_number . 
    "<br/><br/>Business Name: ". $your_business_name . 
    "<br/><br/>Email: ". $senders_email .  
    "<br/><br/>Start Date: ". $your_start_date .
    "<br/><br/>Completion Date: ". $your_completion_date .
    "<br/><br/>Quote with additional information: ". $additional_information;
    
    /* END CODE TO FORMAT MAIL CONTENT */
    
    //$mail_message = stripslashes($mail_message);
    $senders_email = preg_replace("/[^a-zA-Z0-9s.@-_]/", "-", $senders_email);
    $senders_name = preg_replace("/[^a-zA-Z0-9s]/", " ", $senders_name);
    $additional_information = preg_replace("/[^a-zA-Z0-9s]/", " ", $additional_information);
    $headers .= "From: $senders_name <$senders_email> \r\n";
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-type: text/html; charset=utf-8";
    $headers .= "X-Mailer: Mailscript by Dave Hayward http://www.megaginge.info megaginge@gmail.com \r\n";
    mail($sendto_email, $mail_subject, $mail_message, $headers);
    
// THE FOLLOWING CODE SORTS THE REDIRECT TO THANKS PAGE //
 
?>
        <script type="text/javascript">
          <!--
          window.location = "thankyou5.html";
          //-->
        </script>
<?
 
//END OF REDIRECT CODE
 
    }
 
?>

Re: PHP form fields and charset problem

Posted: Sun Jul 05, 2009 8:14 pm
by requinix
You've told the browser to use UTF-8 encoding. Form inputs will be encoded that way.
If you had everything else using that encoding too then you wouldn't have any problems. But not everything is and so you do.

Take a look at this thread.

Re: PHP form fields and charset problem

Posted: Mon Jul 06, 2009 3:58 am
by speed
tasairis wrote:You've told the browser to use UTF-8 encoding. Form inputs will be encoded that way.
If you had everything else using that encoding too then you wouldn't have any problems. But not everything is and so you do.

Take a look at this thread.
I am new to all this so please excuse my lack of knowledge. I thought that everything was encoded the same way, can you explain where I have made a mistake and have things encoded incorrectly.

Rephp help.....

Posted: Mon Jul 06, 2009 6:58 am
by davisjackson
hello there, I am new to this language and am looking for some help. I am creating a form that will select locations from mysql. The table is already populated and I already have the first select defining countries. What I have been trying to do, which I need help on, is create a <select> (for the states) that is dependent off another select(country).
The table is set up like this: location_id(key),country,state,city
this is what I have so for regarding php:
<select name="country">
<?php
mysql_connect(*************************) or die(mysql_error());
mysql_select_db("_root") or die(mysql_error());

$query = ("SELECT country FROM location_root") or die("something messed up");
$result = mysql_query($query);


while ($row = mysql_fetch_array($result))
{

$categories[] = $row['country'];

}

$newData = array_unique($categories);

foreach ($newData as $dropDown)
{
echo "<option>" . $dropDown . "</option>\n";
}

?>
</select>


if anyone could help me, it would be great! thanks



web hosting miami