|
|
|
ทำฟอร์มส่งเมล์แต่ส่งไปแล้วอ่านภาษาไทยไม่ได้ครับ ช่วยดูให้ผมหน่อยครับ |
|
|
|
|
|
|
|
ผมแทรกโค๊ดที่เขียนมาให้ด้วยครับ
ส่วนที่แรก คือส่วนของหน้าหลักฟอร์ม
Code (PHP)
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript">
function sendMail()
{
var req = new ajaxobj();
req.onreadystatechange = function()
{
if(req.readyState==4)
{
document.getElementById("messagealert").innerHTML = req.responseText;
}else{
document.getElementById("messagealert").innerHTML = "<img src='images/indicator.gif' />";
}
}
var first_name = document.getElementById("name").value;
var last_name = document.getElementById("email").value;
var subject = document.getElementById("tel").value;
var message = document.getElementById("enquiry").value;
var a = Math.random();
req.open("GET","mailer.php?a="+a+"&first_name="+first_name+"&last_name="+last_name+"&message="+message+"&subject="+subject,true);
req.send(null);
}
</script>
<!-- End ???????????????? -->
<style type="text/css">
#verify_math{
display:block;
height:21px;
}
#verify_math span{
display:block;
height:21px;
width:30px;
position:relative;
float:left;
text-align:center;
line-height:20px;
color:#000;
}
#verify_math span.digital{
background:url(images/digi_img.jpg) left top no-repeat;
}
#i_verify{
position:relative;
height:15px;
width:35px;
text-align:center;
padding:0;
margin:0;
font-size:15px;
font-weight:bold;
font-family:Tahoma, Geneva, sans-serif;
}
.contact {
margin-right: auto;
margin-left: auto;
}
.styled{
width:350px;
background-color: #3197FB;
border:solid 1px #505050;
color:#033;
font-size:13px;
padding:5px;
margin:5px;
font-family:Trebuchet MS,Arial;
}
</style>
</head>
<body>
<?php
$_SESSION['num_to_check'][0]=rand(1,9);
$_SESSION['num_to_check'][1]=rand(1,9);
?>
<form class="contact" name="contact">
<table width="367">
<tr>
<td><span class="style1">Name:*</span></td>
<td><input type="text" name="name" id="name" class="styled" /></td>
</tr>
<tr>
<td class="style1">Email:*</td>
<td><input type="text" name="email" id="email" class="styled" /></td>
</tr>
<tr>
<td class="style1">Tel:</td>
<td><input type="text" name="tel" id="tel" class="styled" /></td>
</tr>
<tr>
<td valign="top" class="style1">Enquiry:*</td>
<td><textarea id="enquiry" name="enquiry" rows="8" class="styled">Please write your enquiry here.</textarea></td>
</tr>
<tr>
<td class="style1">Tel:</td>
<td>
<div id="verify_math">
<span class="digital" style="background-position:<?=($_SESSION['num_to_check'][0]*-30)?>px 0px;"></span>
<span>+</span>
<span class="digital" style="background-position:<?=($_SESSION['num_to_check'][1]*-30)?>px 0px;"></span>
<span>=</span><span>
<input name="i_verify" type="text" id="i_verify" maxlength="2" />
</span>
</td>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
<td><p>
<input type="reset" value="clear" name="clear" class="clearmes" />
<input type="button" onclick="sendMail()" value="Send Message" name="submit" class="submit" />
<!--<input type="submit" name="button2" id="button2" value="Submit" />-->
</p>
<div style="color:#FF0000;" id="messagealert"></div>
</p>
<p class="h4"> <b> Please Key Number Add.*</b></BR>
<b> Please fill in required fields.*</b></p>
</td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
ส่วนที่สอง เป็น สคริป
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
</head>
<body>
<?php
if($_POST['button2']){
if(isset($_POST['i_verify']) && $_POST['i_verify']==@array_sum($_SESSION['num_to_check']) && $_POST['i_verify']>0 && trim($_POST['i_verify'])!=""){
echo "<span style='color:green;'>Right</span>";
echo"$id";
echo"$name";
$_SESSION['num_to_check'][0]=rand(1,9);
$_SESSION['num_to_check'][1]=rand(1,9);
exit;
}else{
echo "<span style='color:red;'>Wrong</span>";
$_SESSION['num_to_check'][0]=rand(1,9);
$_SESSION['num_to_check'][1]=rand(1,9);
exit;
}
}
if($_POST['button2']){
if(isset($_POST['i_verify']) && $_POST['i_verify']==@array_sum($_SESSION['num_to_check']) && $_POST['i_verify']>0 && trim($_POST['i_verify'])!=""){
echo "<span style='color:green;'>Right</span>";
echo"$id";
echo"$name";
$_SESSION['num_to_check'][0]=rand(1,9);
$_SESSION['num_to_check'][1]=rand(1,9);
exit;
}else{
echo "<span style='color:red;'>Wrong</span>";
$_SESSION['num_to_check'][0]=rand(1,9);
$_SESSION['num_to_check'][1]=rand(1,9);
exit;
}
}
$subjectmail = $_GET['subject'];
$first_name = $_GET['first_name'];
$last_name = $_GET['last_name'];
$messagemail = $_GET['message'];
if(!$_GET['first_name'] || !$_GET['last_name'] || !$_GET['message'] )
{
echo "Please fill out all the required fields<br />Fields marked with * are required.\n";
}
else {
//$emailsend="piko@localhost";
$emailsend="[email protected]";
// if (eregi ("^([a-z0-9_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,4}$", $emailsend))
// {
$from = "$first_name<$last_name>";
$subject= "Messege from $first_name";
$message = "\nName : $first_name\n";
$message .= "Email : $last_name\n";
$message .= "Tel : $subjectmail\n";
$message .= "Message : $messagemail\n";
$headers="From: $from\n";
if (@mail($emailsend, $subject, $message, $headers))
{
echo "Thank you, your email has been sent.";
} else
{
echo "I'm sorry, there seems to have been an error trying to send your email. Please try again.";
}
// }
}
?>
</body>
</html>
ส่วนที่สาม เป็น ajax
Code (JavaScript)
// JavaScript Document
function ajaxobj()
{
try{ return new XMLHttpRequest();} catch (e){
try{ return new ActiveXObject('Msxml2.XMLHTTP');} catch (e){
try{ return new ActiveXObject('Microsoft.XMLHTTP');} catch (e){
alert('XMLHttp not supported');
return null;
}
}
}
}
ตอนนี้เมล์ส่งไปได้แล้วน่ะครับ แต่ไม่อ่านภาษาไทย
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2010-09-06 10:51:50 |
By :
boy415 |
View :
1299 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองแก้จาก
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
เป็น
<meta http-equiv="Content-Type" content="text/html; charset="windows-874">
หรือไม่ก็ tis-620
ในหน้าฟอร์มการส่งเมลล์ ดูสิค่ะ
แล้วตอนส่งก็แปลงจาก windows-874 เป็น UTF-8
|
|
|
|
|
Date :
2010-09-06 11:32:00 |
By :
pp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ได้ครับคุณพี่ ทั้ง เปลียนตาม คห1 และเปลี่ยนเป็น UTF-8 ทุกแพจ ก็ยังส่งเป็นฟอร์นไทยไม่ได้อ่ะครับ พอมีวิธีป่าวครับขอบคุณครับ
|
|
|
|
|
Date :
2010-09-07 09:12:48 |
By :
boy415 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กูรูครับช่วยดูให้ผมหน่อยครับส่งเมล์เป็นภาษาไทย ไม่ได้ครับ เป็นภาษาอะไรไม่รู้อ่ะครับ
|
|
|
|
|
Date :
2010-09-08 08:44:23 |
By :
boy415 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$headers = "From: $from\n";
$headers .= "Content-type: text/html; charset=UTF-8\n";
ส่ง header เป็น UTF-8 ด้วยครับ
|
|
|
|
|
Date :
2010-09-08 09:31:15 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พี่วินครับ ก็ยังไม่ได้เลยครับ
Code (PHP)
$subjectmail = $_GET['subject'];
$first_name = $_GET['first_name'];
$last_name = $_GET['last_name'];
$messagemail = $_GET['message'];
if(!$_GET['first_name'] || !$_GET['last_name'] || !$_GET['message'] )
{
echo "Please fill out all the required fields<br />Fields marked with * are required.\n";
}
else {
//$emailsend="piko@localhost";
$emailsend="[email protected]";
// if (eregi ("^([a-z0-9_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,4}$", $emailsend))
// {
$from = "$first_name<$last_name>";
$subject= "Messege from $first_name";
$message = "\nName : $first_name\n";
$message .= "Email : $last_name\n";
$message .= "Tel : $subjectmail\n";
$message .= "Message : $messagemail\n";
$headers="From: $from\n";
$headers.="Content-type: text/html; charset=UTF-8\n";
/*
$headers = "From: $from\n";
$headers .= "Content-type: text/html; charset=UTF-8\n";
*/
if (@mail($emailsend, $subject, $message, $headers))
{
echo "Thank you, your email has been sent.";
} else
{
echo "I'm sorry, there seems to have been an error trying to send your email. Please try again.";
}
// }
}
?>
|
|
|
|
|
Date :
2010-09-08 14:57:31 |
By :
boy415 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พี่ๆครับช่วยดูโค๊ดให้หน่อยครับ ส่งเมล์เป็นไทยไม่ได้
|
|
|
|
|
Date :
2010-09-09 09:26:02 |
By :
boy415 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|