Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Brak polskich znaków w treści i temacie maila
Forum PHP.pl > Forum > PHP
szorstkiuser
Witam,
Mam problem z polskimi znakami wysyłanymi w temacie jak i treści maila (formularz kontaktowy).
Oto plik php z formularzem:
CODE

<?
// edit these lines
$your_name="Kontakt ze strony www";
$your_email="spec94@o2.pl";
$your_web_site_name="PRIMUS Centrum Szkoleń";
?>

<?php
//If the form is submitted
if(isset($_POST['name'])) {

//Check to make sure that the name field is not empty
if(trim($_POST['name']) === '') {
$hasError = true;
} else {
$name = trim($_POST['name']);
}

//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) === '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
$errorMessage = "Wprowadź poprawny adres e-mail!";
} else {
$email = trim($_POST['email']);
}

//Check to make sure that the phone field is not empty
if(trim($_POST['phone']) === '') {
$hasError = true;
} else {
$phone = trim($_POST['phone']);
}

//company name
$company_name = trim($_POST['company_name']);

//company url
$company_url = trim($_POST['company_url']);


//Check to make sure comments were entered
if(trim($_POST['message']) === '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}



//If there is no error, send the email
if(!isset($hasError)) {

$emailTo = $your_email;
$subject = 'Kontakt ze strony WWW'.$name;

//message body
$body ="Imię i nazwisko: $name \n\n";
$body .="E-mail: $email \n\n";
$body .="Numer telefonu:$phone\n\n";
$body .="Nazwa firmy:$company_name\n\n";
$body .="Strona WWW firmy:$company_url \n\n";
$body .="Wiadomość: $comments";


$headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

mail($emailTo, $subject, $body, $headers);

$emailSent = true;
}
}
?>



<?php if(isset($emailSent) == true) { ?>
<div class="ok_box">
<h3>Dziękujemy,</h3>
<p>Twój e-mail został wysłany, skontaktujemy się Tobą jak najszybciej będzie to możliwe.</p>
</div>
<?php } ?>

<?php if(isset($hasError) ) { ?>
<div class="error_box">
Wystąpił błąd przy wysyłaniu formularza.
<br />
<?php echo $errorMessage;?>
</div>
<?php } ?>
Turson
Nagłowek w wiadomości
  1. $naglowek ="Content-type: text/html; charset=utf-8";
  2. $mail = mail($mail,$temat,$tresc,$naglowek);


+ Polskie znaki w dokumencie PHP
szorstkiuser
kod wyglada teraz tak:
Kod
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<?

$headers ="Content-type: text/html; charset=utf-8";
$email = mail($name,$email,$phone,$company_name,$company_url,$comments);
// edit these lines
$your_name="Kontakt ze strony www";
$your_email="spec94@o2.pl";
$your_web_site_name="PRIMUS Centrum Szkoleń";
?>

<?php
//If the form is submitted
if(isset($_POST['name'])) {

        //Check to make sure that the name field is not empty
        if(trim($_POST['name']) === '') {
            $hasError = true;
        } else {
            $name = trim($_POST['name']);
        }
        
        //Check to make sure sure that a valid email address is submitted
        if(trim($_POST['email']) === '')  {
            $hasError = true;
        } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
            $hasError = true;
            $errorMessage = "Wprowadź poprawny adres e-mail!";
        } else {
            $email = trim($_POST['email']);
        }

        //Check to make sure that the phone field is not empty
        if(trim($_POST['phone']) === '') {
            $hasError = true;
        } else {
            $phone = trim($_POST['phone']);
        }

        //company name
        $company_name = trim($_POST['company_name']);

        //company url
        $company_url = trim($_POST['company_url']);

            
        //Check to make sure comments were entered    
        if(trim($_POST['message']) === '') {
            $hasError = true;
        } else {
            if(function_exists('stripslashes')) {
                $comments = stripslashes(trim($_POST['message']));
            } else {
                $comments = trim($_POST['message']);
            }
        }



        //If there is no error, send the email
        if(!isset($hasError)) {

            $emailTo = $your_email;
            $subject = 'Kontakt ze strony WWW'.$name;
            
            //message body
            $body  ="Imię i nazwisko: $name \n\n";
            $body .="E-mail: $email \n\n";
            $body .="Numer telefonu:$phone\n\n";
            $body .="Nazwa firmy:$company_name\n\n";
            $body .="Strona WWW firmy:$company_url \n\n";
            $body .="Wiadomość: $comments";


            $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
            
            mail($emailTo, $subject, $body, $headers);

            $emailSent = true;
    }
}
?>



<?php if(isset($emailSent) == true) { ?>
    <div class="ok_box">
        <h3>Dziękujemy,</h3>
        <p>Twój e-mail został wysłany, skontaktujemy się Tobą jak najszybciej będzie to możliwe.</p>
    </div>
<?php } ?>

<?php if(isset($hasError) ) { ?>
    <div class="error_box">
        Wystąpił błąd przy wysyłaniu formularza.
        <br />
        <?php echo $errorMessage;?>
    </div>
<?php } ?>

i dalej nie ma polskich znaków..
Turson
Nie rozumiem czegoś w tym kodzie...

Na początku piszesz to
  1. $headers ="Content-type: text/html; charset=utf-8";
  2. $email = mail($name,$email,$phone,$company_name,$company_url,$comments);



A potem to
  1. $emailTo = $your_email;
  2. $subject = 'Kontakt ze strony WWW'.$name;
  3.  
  4. //message body
  5. $body ="Imię i nazwisko: $name \n\n";
  6. $body .="E-mail: $email \n\n";
  7. $body .="Numer telefonu:$phone\n\n";
  8. $body .="Nazwa firmy:$company_name\n\n";
  9. $body .="Strona WWW firmy:$company_url \n\n";
  10. $body .="Wiadomość: $comments";
  11.  
  12.  
  13. $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
  14.  
  15. mail($emailTo, $subject, $body, $headers);


A jeszcze w międzyczasie piszesz to
  1. $email = trim($_POST['email']);


Jaki sens?
com
Turson to się nazywa logika, pewnie kopij wklej biggrin.gif
sajegib
Jeśli chcesz polskie znaki w temacie - wygógluj "base64 encode email subject"
szorstkiuser
proszę o pomoc, dopiero się uczę.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.