ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingเเบบฟอร์มส่งเมล์ ใส่ภาษาไทยแลัว ยึกยืกเซฟไม่ได้ ...PHP
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: เเบบฟอร์มส่งเมล์ ใส่ภาษาไทยแลัว ยึกยืกเซฟไม่ได้ ...PHP  (อ่าน 2129 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
เป็นติ่งไรเนี่ย
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 66
ออฟไลน์ ออฟไลน์

กระทู้: 1,210



ดูรายละเอียด
« เมื่อ: 07 ตุลาคม 2009, 01:07:11 »

ดูให้หน่อยครับ
ใส่ภาษาไทย (ตัวสีเเดง) แล้ว
SAVE ไม่ได้ คับ

ผมลองเเบบนี้
$subject = '=?utf-8?B?'.base64_encode("รายละเอียดส่งให้เรา").'?=';
มันยังเซฟไม่ได้ ภาษาไทยยังเป็นตัวเครื่องหมายคําถาม THX คับ

 wanwan012


อ้างถึง
<?php


// User settings
$to = " thai@hotmail.com";
$subject = "Contact Form";

// Include extra form fields and/or submitter data?
// false = do not include
$extra = array(
   "form_subject"   => true,
   "form_cc"      => true,
   "ip"         => true,
   "user_agent"   => true
);

// Process
$action = isset($_POST["action"]) ? $_POST["action"] : "";
if (empty($action)) {
   // Send back the contact form HTML
   $output = "<div style='display:none'>
   <div class='contact-top'></div>
   <div class='contact-content'>
      <h1 class='contact-title'>ส่งรายละเอียด:</h1>
      <div class='contact-loading' style='display:none'></div>
      <div class='contact-message' style='display:none'></div>
      <form action='#' style='display:none'>
         <label for='contact-name'>*ชื่อ-นามสกุล:</label>
         <input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' />
         <label for='contact-email'>*Email:</label>
         <input type='text' id='contact-email' class='contact-input' name='email' tabindex='1002' />";

   if ($extra["form_subject"]) {
      $output .= "
         <label for='contact-subject'>ชื่อสินค้า:</label>
         <input type='text' id='contact-subject' class='contact-input' name='subject' value='' tabindex='1003' />";
   }

   $output .= "
         <label for='contact-message'>*รายละเอียด:</label>
         <textarea id='contact-message' class='contact-input' name='message' cols='40' rows='4' tabindex='1004'></textarea>
         <br/>";

   if ($extra["form_cc"]) {
      $output .= "
         <label>&nbsp;</label>
         <input type='checkbox' id='contact-cc' name='cc' value='1' tabindex='1005' /> <span class='contact-cc'>Send me a copy</span>
         <br/>";
   }

   $output .= "
         <label>&nbsp;</label>
         <button type='submit' class='contact-send contact-button' tabindex='1006'>Send</button>
         <button type='submit' class='contact-cancel contact-button simplemodal-close' tabindex='1007'>Cancel</button>
         <br/>
         <input type='hidden' name='token' value='" . smcf_token($to) . "'/>
      </form>
   </div>
   
</div>";

   echo $output;
}
else if ($action == "send") {
   // Send the email
   $name = isset($_POST["name"]) ? $_POST["name"] : "";
   $email = isset($_POST["email"]) ? $_POST["email"] : "";
   $subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject;
   $message = isset($_POST["message"]) ? $_POST["message"] : "";
   $cc = isset($_POST["cc"]) ? $_POST["cc"] : "";
   $token = isset($_POST["token"]) ? $_POST["token"] : "";

   // make sure the token matches
   if ($token === smcf_token($to)) {
      smcf_send($name, $email, $subject, $message, $cc);
      echo "OK!..Your message was successfully sent.";
   }
   else {
      echo "Unfortunately, your message could not be verified.";
   }
}

function smcf_token($s) {
   return md5("smcf-" . $s . date("WY"));
}

// Validate and send email
function smcf_send($name, $email, $subject, $message, $cc) {
   global $to, $extra;

   // Filter and validate fields
   $name = smcf_filter($name);
   $subject = smcf_filter($subject);
   $email = smcf_filter($email);
   if (!smcf_validate_email($email)) {
      $subject .= " - invalid email";
      $message .= "\n\nBad email: $email";
      $email = $to;
      $cc = 0; // do not CC "sender"
   }

   // Add additional info to the message
   if ($extra["ip"]) {
      $message .= "\n\nIP: " . $_SERVER["REMOTE_ADDR"];
   }
   if ($extra["user_agent"]) {
      $message .= "\n\nUSER AGENT: " . $_SERVER["HTTP_USER_AGENT"];
   }

   // Set and wordwrap message body
   $body = "From: $name\n\n";
   $body .= "Message: $message";
   $body = wordwrap($body, 70);

   // Build header
   $headers = "From: $email\n";
   if ($cc == 1) {
      $headers .= "Cc: $email\n";
   }
   $headers .= "X-Mailer: PHP/SimpleModalContactForm";

   // UTF-8
   if (function_exists('mb_encode_mimeheader')) {
      $subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");
   }
   else {
      // you need to enable mb_encode_mimeheader or risk
      // getting emails that are not UTF-8 encoded
   }
   $headers .= "MIME-Version: 1.0\n";
   $headers .= "Content-type: text/plain; charset=utf-8\n";
   $headers .= "Content-Transfer-Encoding: quoted-printable\n";

   // Send email
   @mail($to, $subject, $body, $headers) or
      die("Unfortunately, a server issue prevented delivery of your message.");
}

// Remove any un-safe values to prevent email injection
function smcf_filter($value) {
   $pattern = array("/\n/","/\r/","/content-type:/i","/to:/i", "/from:/i", "/cc:/i");
   $value = preg_replace($pattern, "", $value);
   return $value;
}

// Validate email address format in case client-side validation "fails"
function smcf_validate_email($email) {
   $at = strrpos($email, "@");

   // Make sure the at (@) sybmol exists and 
   // it is not the first or last character
   if ($at && ($at < 1 || ($at + 1) == strlen($email)))
      return false;

   // Make sure there aren't multiple periods together
   if (preg_match("/(\.{2,})/", $email))
      return false;

   // Break up the local and domain portions
   $local = substr($email, 0, $at);
   $domain = substr($email, $at + 1);


   // Check lengths
   $locLen = strlen($local);
   $domLen = strlen($domain);
   if ($locLen < 1 || $locLen > 64 || $domLen < 4 || $domLen > 255)
      return false;

   // Make sure local and domain don't start with or end with a period
   if (preg_match("/(^\.|\.$)/", $local) || preg_match("/(^\.|\.$)/", $domain))
      return false;

   // Check for quoted-string addresses
   // Since almost anything is allowed in a quoted-string address,
   // we're just going to let them go through
   if (!preg_match('/^"(.+)"$/', $local)) {
      // It's a dot-string address...check for valid characters
      if (!preg_match('/^[-a-zA-Z0-9!#$%*\/?|^{}`~&\'+=_\.]*$/', $local))
         return false;
   }

   // Make sure domain contains only valid characters and at least one period
   if (!preg_match("/^[-a-zA-Z0-9\.]*$/", $domain) || !strpos($domain, "."))
      return false;   

   return true;
}

exit;

?>

บันทึกการเข้า
เป็นติ่งไรเนี่ย
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 66
ออฟไลน์ ออฟไลน์

กระทู้: 1,210



ดูรายละเอียด
« ตอบ #1 เมื่อ: 07 ตุลาคม 2009, 11:25:41 »

ดัน..อวัศวิน
 wanwan013 wanwan013
บันทึกการเข้า
mikeyx
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 268
ออฟไลน์ ออฟไลน์

กระทู้: 4,008



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 07 ตุลาคม 2009, 12:38:01 »

 Huh? Huh? นึกว่าส่งภาษาไทยไม่ได้
« แก้ไขครั้งสุดท้าย: 07 ตุลาคม 2009, 14:16:43 โดย mikeyx » บันทึกการเข้า
kanin2604
ก๊วนเสียว
*

พลังน้ำใจ: 16
ออฟไลน์ ออฟไลน์

กระทู้: 420



ดูรายละเอียด เว็บไซต์
« ตอบ #3 เมื่อ: 07 ตุลาคม 2009, 16:49:04 »

เข้ามาดู
บันทึกการเข้า

nuijang24
Newbie
*

พลังน้ำใจ: 3
ออฟไลน์ ออฟไลน์

กระทู้: 21



ดูรายละเอียด เว็บไซต์
« ตอบ #4 เมื่อ: 07 ตุลาคม 2009, 18:17:42 »

งงคำถามเหมือนกันครับ น่าจะเป็น ?? ตอนที่ submit ไปแล้วใช่มั้ยครับ

เพราะงั้น ลองใช้ function utf8_to_tis620 พวกนี้แปลง ข้อมูลที่ได้จาก textbox ซึ่ง encode UTF-8 อยู่ให้เป็น tis-620 ดูนะครับ
// สำหรับแปลง UTF-8 เป็น tis-620
function utf8_to_tis620($string)
{
    $str = $string;
    $res = "";
    for ($i = 0; $i < strlen($str); $i++) {
      if (ord($str[$i]) == 224) {
        $unicode = ord($str[$i+2]) & 0x3F;
        $unicode |= (ord($str[$i+1]) & 0x3F) << 6;
        $unicode |= (ord($str[$i]) & 0x0F) << 12;
        $res .= chr($unicode-0x0E00+0xA0);
        $i += 2;
      } else {
        $res .= $str[$i];
      }
    }
    return $res;
}

// สำหรับแปลง tis-620 เป็น utf-8
function tis620_to_utf8($text) {
  $utf8 = "";
  for ($i = 0; $i < strlen($text); $i++) {
    $a = substr($text, $i, 1);
    $val = ord($a);

    if ($val < 0x80) {
      $utf8 .= $a;
    } elseif ((0xA1 <= $val && $val < 0xDA) || (0xDF <= $val && $val <= 0xFB)) {
      $unicode = 0x0E00+$val-0xA0;       $utf8 .= chr(0xE0 | ($unicode >> 12));
      $utf8 .= chr(0x80 | (($unicode >> 6) & 0x3F));
      $utf8 .= chr(0x80 | ($unicode & 0x3F));
    }
  }
  return $utf8;
}
ได้ผลยังไง บอกด้วยเด้อ
บันทึกการเข้า

หน้า: [1]   ขึ้นบน
พิมพ์