Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UTF-8(tj. hr slova), kako?
Author Message
Son Goku Offline
Novi korisnik
*

Posts: 41
Joined: Jan 2008
Reputation: 0
Post: #1
UTF-8(tj. hr slova), kako?
Pozdrav. Imam ovaj dio kontakt skripte:

PHP Code:
<?php
$contact_name 
$_POST['name'];
$contact_email $_POST['email'];
$contact_message $_POST['message'];

if( 
$contact_name == true )
{
    
$sender $contact_email;
    
$receiver "xxx@yyy.hr";
    
$email_body "Ime: $contact_name \nEmail: $sender \n\nPoruka: $contact_message";        
    
$extra "From: $sender\r\n" "Reply-To: $sender \r\n" "X-Mailer: PHP/" phpversion();

    if( 
mail$receiver"Kontakt"$email_body$extra ) ) 
    {
        echo 
"success=yes";
    }
    else
    {
        echo 
"success=no";
    }
}
?>

i neznam gdje bi i kako da ubacim ono UTF-8 kodiranje da mi se u mailu koji dobijem prikazu nasa slovaConfused

Hvala :)
30-12-2008 11:08 AM
Find all posts by this user Quote this message in a reply
Gogy Offline
____
*

Posts: 2,378
Joined: Feb 2006
Post: #2
RE: UTF-8(tj. hr slova), kako?
Probaj ovako

PHP Code:
<?php
$contact_message 
.= "Content-Type: text/html; charset=UTF-8\n";
?>

Pravila foruma | Twitter - Facebook - Google+ |


Radar404 <- moj blog
30-12-2008 11:38 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Son Goku Offline
Novi korisnik
*

Posts: 41
Joined: Jan 2008
Reputation: 0
Post: #3
RE: UTF-8(tj. hr slova), kako?
Hvala puno, uspio sam ovako:

PHP Code:
<?php
$contact_name 
$_POST['name'];
$contact_email $_POST['email'];
$contact_message $_POST['message'];

if( 
$contact_name == true )
{
    
$sender $contact_email;
    
$receiver "xxx@yyy.hr";
    
$email_body "Ime: $contact_name \nEmail: $sender \n\nPoruka: $contact_message";        
    
$extra "From: $sender\r\n" "Reply-To: $sender \r\n" "X-Mailer: PHP/" phpversion();
    
$extra .= 'MIME-Version: 1.0' "\r\n";
    
$extra .= 'Content-type: text/plain; charset=UTF-8' "\r\n";

    if( 
mail$receiver"Životinje - Kontakt"$email_body$extra ) ) 
    {
        echo 
"success=yes";
    }
    else
    {
        echo 
"success=no";
    }
}
?>

sad je u poruci(u body-u) sve super, dobijem hr slova, ali jos mi samo fali u subjectu, u ovom slucaju je to "Životinje - Kontakt", tu mi nece ispisati Ž, kako da jos samo to namijestim?

Hvala :)
30-12-2008 12:30 PM
Find all posts by this user Quote this message in a reply
Gogy Offline
____
*

Posts: 2,378
Joined: Feb 2006
Post: #4
RE: UTF-8(tj. hr slova), kako?
Nisam siguran, ali probaj ovako:

PHP Code:
$subjectmb_encode_mimeheader("Životinje - Kontakt","UTF-8""B""\n"); 

Pravila foruma | Twitter - Facebook - Google+ |


Radar404 <- moj blog
30-12-2008 01:28 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Son Goku Offline
Novi korisnik
*

Posts: 41
Joined: Jan 2008
Reputation: 0
Post: #5
RE: UTF-8(tj. hr slova), kako?
nece, izbaci mi u subject:®ivotinje - Kontakt
30-12-2008 02:00 PM
Find all posts by this user Quote this message in a reply
Gogy Offline
____
*

Posts: 2,378
Joined: Feb 2006
Post: #6
RE: UTF-8(tj. hr slova), kako?
Hmm... a probaj onda ovako:

PHP Code:
$subject "=?UTF-8?Q?".$subject."?="

Ako ne radi, pokušat ću ja sad poslje nove godine, ako ti to nije predugo za čekat, napravit neki primjer... Jer da ti pravo kažem ni ja nisam baš siguran kako to ide.

Pravila foruma | Twitter - Facebook - Google+ |


Radar404 <- moj blog
30-12-2008 10:45 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Son Goku Offline
Novi korisnik
*

Posts: 41
Joined: Jan 2008
Reputation: 0
Post: #7
RE: UTF-8(tj. hr slova), kako?
Pozdrav, hvala na pomoci, ali evo nikako da mi uspije, probao sam ovako:

PHP Code:
<?php
$contact_name 
$_POST['name'];
$contact_email $_POST['email'];
$contact_message $_POST['message'];

if( 
$contact_name == true )
{
    
$subjectmb_encode_mimeheader("Životinje - Kontakti","UTF-8""B""\n");
    
$sender $contact_email;
    
$receiver "xxx@yyy.hr";
    
$email_body "Ime: $contact_name \nEmail: $sender \n\nPoruka: $contact_message";        
    
$extra "From: $sender\r\n" "Reply-To: $sender \r\n" "X-Mailer: PHP/" phpversion();
    
$extra .= 'MIME-Version: 1.0' "\r\n";
    
$extra .= 'Content-type: text/plain; charset=UTF-8' "\r\n";

    if( 
mail$receiver$subject$email_body$extra ) ) 
    {
        echo 
"success=yes";
    }
    else
    {
        echo 
"success=no";
    }
}
?>

probo sam i sa:

PHP Code:
<?php
$contact_name 
$_POST['name'];
$contact_email $_POST['email'];
$contact_message $_POST['message'];

if( 
$contact_name == true )
{
    
$subject "=?UTF-8?Q?".$subject."?="
    
$sender $contact_email;
    
$receiver "xxx@yyy.hr";
    
$email_body "Ime: $contact_name \nEmail: $sender \n\nPoruka: $contact_message";        
    
$extra "From: $sender\r\n" "Reply-To: $sender \r\n" "X-Mailer: PHP/" phpversion();
    
$extra .= 'MIME-Version: 1.0' "\r\n";
    
$extra .= 'Content-type: text/plain; charset=UTF-8' "\r\n";

    if( 
mail$receiver"Životinje - Kontakti"$email_body$extra ) ) 
    {
        echo 
"success=yes";
    }
    else
    {
        echo 
"success=no";
    }
}
?>
ne sljaka na zalost, imas kakvu jos ideju? tnx puno :)
(This post was last modified: 08-01-2009 11:26 AM by Son Goku.)
08-01-2009 11:25 AM
Find all posts by this user Quote this message in a reply
vetzo Offline
Novi korisnik
*

Posts: 1
Joined: Feb 2011
Reputation: 0
Post: #8
RE: UTF-8(tj. hr slova), kako?
vjerojatno si do sad rjesio ali cisto da stavim rjesenje jer sam ja izgubio sat vremena guglajuci:

PHP Code:
mail($to,'=?UTF-8?B?'.base64_encode($subject).'?=',$message,$headers

a evo i kompletnog htmla i phpa ... dakle u formu je ukljucena i mala JS skripta koja provjerava dali su obavezna polja ispunjena [btw. sajt je radjen za tal trziste pa su i u alertu tekstovi na talijanskom], a u mailu su dodani i ip posiljatelja i neke druge sitnice koje slobodno izbacite...

dakle
forma.html
PHP Code:
<script type="text/javascript">
function 
validate_required(field,alerttxt)
{
with (field)
  {
  if (
value==null||value=="")
    {
    
alert(alerttxt);return false;
    }
  else
    {
    return 
true;
    }
  }
}

function 
validate_form(thisform)
{
with (thisform)
  {
  if (
validate_required(ime,"Vi preghiamo di inserire il vostro nome!")==false)
  {
ime.focus();return false;}
  if (
validate_required(prezime,"Vi preghiamo di inserire il vostro cognome!")==false)
  {
prezime.focus();return false;}
  if (
validate_required(telefon,"Vi preghiamo di inserire il vostro numero di telefono!")==false)
  {
telefon.focus();return false;}
  if (
validate_required(poruka,"Vi preghiamo di inserire il vostro messaggio!")==false)
  {
poruka.focus();return false;}
  }
}
</script>

<form name="info" method="post" action="obrada.php" enctype="multipart/form-data"  onsubmit="return validate_form(this)"> 

<p class="kontakt">Nome:<font>*</font><input name="ime" type="text" class="kontaktforma" size="60" /></p>

<p class="kontakt">Cognome:<font>*</font><input name="prezime" type="text" class="kontaktforma" size="60" /></p>

<p class="kontakt">Eta:<input name="starost" type="text" class="kontaktforma" size="60" /></p>

<p class="kontakt">Localita:<input name="grad" type="text" class="kontaktforma" size="60" /></p>

<p class="kontakt">Telefono:<font>*</font><input name="telefon" type="text" class="kontaktforma" size="60" /></p>

<p class="kontakt">Indirizzo e-mail:<input name="email" type="text" class="kontaktforma" size="60" /></p>


<p class="kontakt">Messaggio:<font color="red">*</font><textarea name="poruka" class="kontaktformapolje" ></textarea></p>

<p class="kontakt">Allega la panoramica o il vecchio preventivo:<input name="attachment" type="file" class="kontaktformafile" size="12" /></p>
        <script type="text/javascript">
            var adr = location.href;
            document.write ("<input type=\"hidden\" name=\"adresa\" value=\""+adr+"\">");
            var ipadr = "<?php echo $_SERVER['REMOTE_ADDR']?>";
            document.write ("<input type=\"hidden\" name=\"ipadresa\" value=\""+ipadr+"\">");
            var agentmoj = navigator.userAgent;
            document.write ("<input type=\"hidden\" name=\"agent\" value=\""+agentmoj+"\">");
            var nav= navigator.geolocation;
        </script>

<input type="submit" value="Invia" name="submit" class="wpcf7-submit" /></div>
</form> 

i obrada.php
PHP Code:
<?php


// enquiry form validation

function process_form() {
    
// Read POST request params into global vars
    // FILL IN YOUR EMAIL
    
$emailfrom "webforma@nesto.com";
    
$to "nesto@nesto.com,";
    
$adresa stripslashes($_POST['adresa']);
    
$jezik "it";
    
$drzava "Italija";
    
$ipadresa stripslashes($_POST['ipadresa']);
    
$agent stripslashes($_POST['agent']);
    
$ime stripslashes($_POST['ime']);
    
$prezime stripslashes($_POST['prezime']);
    
$starost stripslashes($_POST['starost']);
    
$grad stripslashes($_POST['grad']);
    
$telefon stripslashes($_POST['telefon']);
    
$email stripslashes($_POST['email']);
    
$poruka stripslashes($_POST['poruka']);
    
$poruka ereg_replace"\r\n"" "$poruka);
            
    if (
$email != "")
        
$subject "Upit sa nestoIT od $ime $prezime <$email>";
    else    
        
$subject "Upit sa nestoIT od $ime $prezime";
     
    





    
// Allowed file types. add file extensions WITHOUT the dot.
    //$allowtypes=array("zip", "rar", "doc", "pdf");
    
    // Require a file to be attached: false = Do not allow attachments true = allow only 1 file to be attached
    //$requirefile="true";
    
    // Maximum file size for attachments in KB NOT Bytes for simplicity. MAKE SURE your php.ini can handel it,
    // post_max_size, upload_max_filesize, file_uploads, max_execution_time!
    // 2048kb = 2MB,       1024kb = 1MB,     512kb = 1/2MB etc..
    //$max_file_size="1024";
    
    // Thank you message
    
$thanksmessage="Your email has been sent, we will respond shortly.";

    
$errors = array(); //Initialize error array

    //checks for a name
    //if (empty($_POST['namefrom']) ) {
    //    $errors[]='You forgot to enter your name';
    //    }

    //checks for an email
    //if (empty($_POST['emailfrom']) ) {
    //    $errors[]='You forgot to enter your email';
    //    } else {

    //    if (!eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['emailfrom'])))) {
    //        $errors[]='Please enter a valid email address';
    //    } // if eregi
    //    } // if empty email

    //checks for a subject
    //if (empty($_POST['subject']) ) {
    //    $errors[]='You forgot to enter a subject';
    //    }

    //checks for a message
    //if (empty($_POST['comments']) ) {
    //    $errors[]='You forgot to enter your comments';
    //    }
        
     // checks for required file
    // http://amiworks.co.in/talk/handling-file-uploads-in-php/
    //if($requirefile=="true") {
    //    if($_FILES['attachment']['error']==4) {
    //        $errors[]='You forgot to attach a file';
    //    }
    //}
        
    //checks attachment file
    // checks that we have a file
    
if((!empty($_FILES["attachment"])) && ($_FILES['attachment']['error'] == 0)) {
            
// basename -- Returns filename component of path
            
$filename basename($_FILES['attachment']['name']);
            
$ext substr($filenamestrrpos($filename'.') + 1);
            
$filesize=$_FILES['attachment']['size'];
            
$max_bytes=$max_file_size*1024;
            
            
//Check if the file type uploaded is a valid file type. 
        //    if (!in_array($ext, $allowtypes)) {
        //    $errors[]="Invalid extension for your file: <strong>".$filename."</strong>";
                
        // check the size of each file
        //} elseif($filesize > $max_bytes) {
        //        $errors[]= "Your file: <strong>".$filename."</strong> is to big. Max file size is ".$max_file_size."kb.";
        //    }
            
    
// if !empty FILES

    
if (empty($errors)) { //If everything is OK
        
        // send an email
        // Obtain file upload vars
        
$fileatt      $_FILES['attachment']['tmp_name'];
        
$fileatt_type $_FILES['attachment']['type'];
        
$fileatt_name $_FILES['attachment']['name'];
        
        
// Headers
        
$headers "From: $emailfrom";
        
        
// create a boundary string. It must be unique
          
$semi_rand md5(time());
          
$mime_boundary "==Multipart_Boundary_x{$semi_rand}x";

          
// Add the headers for a file attachment
          
$headers .= "\nMIME-Version: 1.0\n" .
                      
"Content-Type: multipart/mixed;\n" .
                      
" boundary=\"{$mime_boundary}\"";

          
// Add a multipart boundary above the plain message
          
$message ="This is a multi-part message in MIME format.\n\n";
          
$message.="--{$mime_boundary}\n";
          
$message.="Content-Type: text/plain; charset=\"utf-8\"\n";
          
$message.="Content-Transfer-Encoding: 7bit\n\n";
          
$message.="Referer: ".$adresa."\n";
          
$message.="Jezik: ".$jezik."\n";
          
$message.="Ip adresa: ".$ipadresa."\n";
          
$message.="Država: ".$drzava."\n";
          
$message.="User-agent: ".$agent."\n\n";    
          
          
$message.="Ime: ".$ime."\n";
          
$message.="Prezime: ".$prezime."\n";
          
$message.="Starost: ".$starost."\n";
          
$message.="Grad: ".$grad."\n";
          
$message.="Telefon: ".$telefon."\n";    
          
$message.="E-mail: ".$email."\n\n";
        
          
$message.="Poruka: "."\n".$poruka."\n\n";
        

        
        if (
is_uploaded_file($fileatt)) {
          
// Read the file to be attached ('rb' = read binary)
          
$file fopen($fileatt,'rb');
          
$data fread($file,filesize($fileatt));
          
fclose($file);

          
// Base64 encode the file data
          
$data chunk_split(base64_encode($data));

          
// Add file attachment to the message
          
$message .= "--{$mime_boundary}\n" .
                      
"Content-Type: {$fileatt_type};\n" .
                      
" name=\"{$fileatt_name}\"\n" .
                      
//"Content-Disposition: attachment;\n" .
                      //" filename=\"{$fileatt_name}\"\n" .
                      
"Content-Transfer-Encoding: base64\n\n" .
                      
$data "\n\n" .
                      
"--{$mime_boundary}--\n";
        }
        
        
        
// Send the completed message
        
        //$envs = array("HTTP_USER_AGENT", "REMOTE_ADDR", "REMOTE_HOST");
        //foreach ($envs as $env)
        //$message .= "$env: $_SERVER[$env]\n";


           
mb_language("hr");

        if(!
mail($to,'=?UTF-8?B?'.base64_encode($subject).'?=',$message,$headers)) {
            
header("Location: http://www.nesto.com/it/errore");
        } else {
            
header("Location: http://www.nesto.com/it/grazie/");

            
        } 
// end of if !mail
        
    
}

// end of process_form()

process_form();
?>

btw. ak vam trebaju neke stvari koje meni nisu potrebne bile samo ih odkomentirajte :)
(This post was last modified: 11-02-2011 03:10 PM by vetzo.)
11-02-2011 03:01 PM
Find all posts by this user Quote this message in a reply
Gogy Offline
____
*

Posts: 2,378
Joined: Feb 2006
Post: #9
RE: UTF-8(tj. hr slova), kako?
Kasniš samo dvije godine ali nema veze Lol

Pravila foruma | Twitter - Facebook - Google+ |


Radar404 <- moj blog
11-02-2011 04:51 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)