小弟初學 PHP 遇到疑難,還請諸位學長指點一二

小弟在 linux 系統下寫了一個 php 程式,就只是簡單的 form to mail ,同樣的內容,寄到不同的信箱
包括:
GMail
Hotmail
易達網
Synology NAS 的 Mail Server
Exchange 2003
寄到 GMail ,使用 GMail Web Mail 去看信件內容,全部資訊的正常
使用 Android 手機內建的 GMail Apps 去看,也都正常
寄到 Hotmail,使用 Hotmail Web Mail 去看信也正常
使用 Windows Live Mail 去看信也正常
使用 Android Hotmail Apps 去看信也正常
寄到易達網,使用易達網Web Mail 去看信也正常
使用Android 手機內建的"電子郵件" Apps 去看信也正常
寄到Synology NAS,使用Roundcube Web Mail 去看信也正常
使用Android 手機內建的"電子郵件" Apps 去看信也正常
寄到 Exchange 2003,使用 MS Outlook 去看信也正常
使用OWA 去看信也正常
使用Android 手機內建的"電子郵件" Apps 去看信卻都是亂碼! 小弟無法理解的是,同樣一封信,寄到易達網、寄到 Synology NAS ,用 Android 手機的同樣一個 Apps "電子郵件" 收信,都是正常
寄到 Exchange 2003 ,用 Android 手機的同樣一個 Apps "電子郵件" 收信,卻是亂碼,
而且這封信是保存在 Exchange Server 上的(不是收到個人資料夾)
用 MS Outlook 2003、OWA 去看信,內容都是正常的...
請教一下,要怎麼樣才能讓寄到 Exchange 2003 的信,用 Android 電子郵件 Apps 收件是正常的?
這個問題也讓我很困擾,因為我們老董,經常用 HTC 手機,收到朋友從 HiNet WebMail 寄到公司的 Exhcnage 2003 的信,都是亂碼....
<?php
define( 'LNCR', linebreak() );
function linebreak(){
$os = strtolower(PHP_OS);
switch( true ){
case ("\\" == DIRECTORY_SEPARATOR) : // windows
return "\x0d\x0a" ;
case ( strpos($os, 'darwin') !== false ) : // Mac
return "\x0d" ;
default :
return "\x0a" ; // *nix
};
}
$mail_from = 'nobody@company.com.tw';
$email_subject = '=?UTF-8?B?' . base64_encode('線上報名') . '?=';
$email_to = '=?UTF-8?B?' . base64_encode('大哥') . '?=<bigbrother@company.com.tw>';
$email_cc = '=?UTF-8?B?' . base64_encode('小妹') . '?=<sister@gmail.com>,' . LNCR;
$email_cc .= ' =?UTF-8?B?' . base64_encode('老三') . '?=<third@yahoo.com.tw>,' . LNCR;
$email_cc .= ' =?UTF-8?B?' . base64_encode('老三') . '?=<third@synologynas.com.tw>,' . LNCR;
$email_cc .= ' =?UTF-8?B?' . base64_encode('老四') . '?=<jumior@synologynas.com.tw>';
$email_bcc = '=?UTF-8?B?' . base64_encode('湯包') . '?=<tombo@hotmail.com>,' . LNCR;
$email_bcc .= ' =?UTF-8?B?' . base64_encode('湯包') . '?=<tombo@gmail.com>,' . LNCR;
$email_bcc .= ' =?UTF-8?B?' . base64_encode('湯包') . '?=<tombo@url.com.tw>,' . LNCR;
$email_bcc .= ' =?UTF-8?B?' . base64_encode('湯包') . '?=<tombo@exchange.com.tw>,' . LNCR;
$email_bcc .= ' =?UTF-8?B?' . base64_encode('湯包') . '?=<tombo@synologynas.com.tw>';
function died($error) {
// your error code can go here
echo "很抱歉您填寫的資料錯誤";
echo "錯誤訊息如下.<br /><br />";
echo $error."<br /><br />";
echo "請<a href='mailform.php'>回到上一頁</a>重新輸入<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['gender']) ||
!isset($_POST['ageRad']) ||
!isset($_POST['mobile']) ||
!isset($_POST['agreeRad']) ||
died('請您確實填寫所有欄位,謝謝!');
}
$name = $_POST['name']; // required
$gender = $_POST['gender']; // required
$ageRad = $_POST['ageRad']; // not required
$email_from = $_POST['email']; // required
$mobile = $_POST['mobile']; // not required
$agreeRad = $_POST['agreeRad']; // 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 .= '電子郵件地址格式錯誤,請再確認一次.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href", "select", "insert");
return str_replace($bad,"",$string);
}
$boundary = uniqid('np');
// create email headers
$headers = 'MIME-Version: 1.0' . LNCR;
// $headers .= 'Content-type: text/html; charset=UTF-8' . LNCR;
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . LNCR;
$headers .= 'From: ' . $mail_from . LNCR;
$headers .= 'To: ' . $email_to . LNCR;
$headers .= 'Cc: ' . $email_cc . LNCR;
$headers .= 'Bcc: ' . $email_bcc . LNCR;
$headers .= 'Reply-To: ' . $mail_from . LNCR;
// create email body
//
$email_message = 'This is a MIME encoded message.';
$email_message .= LNCR . LNCR . '--' . $boundary . LNCR;
$email_message .= 'Content-type: text/plain;charset=utf-8' . LNCR . LNCR;
$email_message .= 'This is the text/plain version.';
$email_message .= '線上報名資訊:' . LNCR . LNCR;
$email_message .= '姓名:' . clean_string($name) . LNCR;
$email_message .= '性別:' . clean_string($gender) . LNCR;
$email_message .= '年齡:' . clean_string($ageRad) . LNCR;
$email_message .= '電子信箱:' . clean_string($email_from) . LNCR;
$email_message .= '手機:' . clean_string($mobile) . LNCR;
$email_message .= '是否同意:' . clean_string($agreeRad) . LNCR;
$email_message .= LNCR . LNCR . '--' . $boundary . LNCR;
$email_message .= 'Content-type: text/html;charset=utf-8' . LNCR . LNCR;
$email_message .= '<b>線上報名資訊</b>:<br /><br />';
$email_message .= '姓名:<font color="blue">' . clean_string($name) . '</font><br />';
$email_message .= '性別:<font color="blue">' . clean_string($gender) . '</font><br />';
$email_message .= '年齡:<font color="blue">' . clean_string($ageRad) . '</font><br />';
$email_message .= '電子信箱:<font color="blue">' . clean_string($email_from) . '</font><br />';
$email_message .= '手機:<font color="blue">' . clean_string($mobile) . '</font><br />';
$email_message .= '是否同意:<font color="blue">' . clean_string($agreeRad) . '</font><br />';
$email_message .= LNCR . LNCR . '--' . $boundary . '--';
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<link href="css/t_layout.css" rel="stylesheet" type="text/css" />
<link href="css/t_menu.css" rel="stylesheet" type="text/css" />
<link href="css/slideshow.css" rel="stylesheet" type="text/css" />
<script type=text/javascript src="js/jquery.1.6.4.js"></script>
<script type=text/javascript src="js/jquery.slideshow.lite.js"></script>
<script type=text/javascript src="js/jquery-latest.min.js"></script>
<script src="kent.js"></script>
<script type="text/javascript">
$(function(){
// 幫 #menu li 加上 hover 事件
$('#menu>li').hover(function(){
// 先找到 li 中的子選單
var _this = $(this),
_subnav = _this.children('ul');
// 變更目前母選項的背景顏色
// 同時顯示子選單(如果有的話)
_this.css('backgroundColor', '#0084c4').siblings().css('backgroundColor', '');
_subnav.css('display', 'block');
} , function(){
// 同時隱藏子選單(如果有的話)
// 也可以把整句拆成上面的寫法
$(this).children('ul').css('display', 'none');
});
// 取消超連結的虛線框
$('a').focus(function(){
this.blur();
});
});
</script>
<style type="text/css">
<!--
.style1 {color: #990000}
-->
</style>
<div id="wrapper" align="center">
<div id="head">
<?php include("_header.php");?>
</div>
<div id="main_menu">
<div id="main_nav">
<?php include("_menu.php");?>
<div class="a"></div>
</div>
</div>
<div id="content">
<div align="center">
<div id="text">
<div id="text_pic1"><img src="images/tyy.jpg" /></div>
<div id="text_success" align="left">
<!-- 成功傳輸表單的訊息 -->
成功 !!<br /><br />
您已完成線上報名。
</div>
<!-- 頁腳 -->
</div>
</div>
</div>
<div id="footer" align="left">
<div class="footer_block">
<?php include("_foot.php");?>
<div class="footer_logo"><a href="http://www.company.com.tw/" target="_blank"><img src="images/logo.png" border="0" /></a></div>
<div class="footer_fb"><a href="http://www.facebook.com" target="_blank"><img src="images/fb.png" border="0" /></a></div>
<div class="footer_info2">版權所有 禁止轉載 © 2012, Company All Rights Reserved.</div>
</div>
</div>
</div>