 |
รบกวนช่วยดู code หน่อยครับ เกี่ยวกับการส่ง Email ส่งเป็นภาษาไทยไม่ได้ |
|
 |
|
|
 |
 |
|
คือว่า เขียน Code สำหรับส่ง Email ใช้งานได้หมดแล้วครับ แต่ มีปัญหาตรงที่ ส่งภาษาไทยไม่ได้ รบกวนช่วยดู code หน่อยครับ
Code (PHP)
<?
ob_start();
?>
<?php
$temp=$_POST['emailto'];
echo $temp;
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = $temp;
$email_subject = "EMAIL FROM CUSTOMER";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n" ;
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<?php
}
?>
<?
header("Location: http://www.chadahouse.com/contact.htm");
?>
Tag : PHP, Windows
|
|
 |
 |
 |
 |
Date :
2012-07-10 09:53:26 |
By :
trowabartuns |
View :
1099 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code
<?php
//define('DEBUG',true);
function ct($ct,$a){
$s = "Content-Type: $ct";
foreach($a as $k=>$v){
$s .= ";\r\n\t$k=\"$v\"";
}
return "$s\r\n";
}
function cte($cte){
return "Content-Transfer-Encoding: $cte\r\n";
}
function enc($s){
return '=?UTF-8?B?'.base64_encode($s).'?=';
}
function mail_utf8($to,$from,$subject,$text,$html)
{
$hash = md5(date('r', time()));
$b1 = 'b1_'.$hash; $bb1 = "\r\n--$b1\r\n"; $bb1e = "\r\n--$b1--\r\n";
$b2 = 'b2_'.$hash; $bb2 = "\r\n--$b2\r\n"; $bb2e = "\r\n--$b2--\r\n";
if (strpos($from,'<')){
list($name,$email)=explode('<',$from);
$from = enc($name).' <'.$email;
}
if (strpos($to,'<')){
list($name,$email)=explode('<',$to);
$to = enc($name).' <'.$email;
}
$h = "From: $from\r\n";
$h .= "Reply-To: $from\r\n";
$h .= "MIME-Version: 1.0\r\n";
$h .= ct('multipart/related',array(
'type'=>'text/html',
'boundary'=>$b1
));
$m = $bb1;
$m .= ct('multipart/alternative',array('boundary'=>$b2));
$m .= $bb2;
$m .= ct('text/plain',array('charset'=>'UTF-8'));
$m .= cte('8bit');
$m .= "\r\n$text\r\n";
$m .= $bb2;
$m .= ct('text/html',array('charset'=>'UTF-8'));
$m .= cte('8bit');
$m .= "\r\n$html\r\n";
$m .= $bb2e;
$m .= $bb1e;
$subject = enc($subject);
if (defined('DEBUG')){
echo "<pre>\r\n";
echo "$to\r\n$subject\r\n$h\r\n$m";
echo '</pre>';
} else {
return @mail( $to, $subject, $m, $h );
}
}
mail_utf8
(
'คุณสวัสดีครับ <[email protected]>',
'คุณสวัสดีค่ะ <[email protected]>',
'หัวข้อ',
'text ครับ',
'<body><b>html</b>ครับ</body>'
);
?>
ข้อมูลจาก http://web-programming-bookmark.blogspot.com/2010/12/php-send-mail-utf-8.html
|
 |
 |
 |
 |
Date :
2012-07-10 09:59:04 |
By :
kongoon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|