khmer unicode utf-8 PHP发送邮件无效

时间:2017-09-18 06:28:20

标签: php mysql

这是通过php代码发送邮件后的结果。而且接收电子邮件我看到“????????”当我用高棉unicode发送。

下面的表格详情。     名称: ??? ??????     性别:???? :女     电子邮件:Chhangtongeur@gmail.com     电话:0969893036     出生日期:1999-11-12     课程:??????????????????     转变:????????? ??? ???????????????? : 星期一星期四     时间:06:00 - 07:00

Php发送邮件代码

    <?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "info@ats-school.com, info@ats-school.com";
    $email_subject ="Register From Website:";

    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['fullName']) ||
        !isset($_POST['sex']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['birthDate']) ||
        !isset($_POST['course']) ||
        !isset($_POST['shift']) ||
        !isset($_POST['time'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }
    $fullName = utf8_decode($_POST['fullName']); // required
    $sex = utf8_decode($_POST['sex']); // required
    $email = utf8_decode($_POST['email']); // not required
    $telephone = utf8_decode($_POST['telephone']); // required
    $birthDate = utf8_decode($_POST['birthDate']); // required
    $course = utf8_decode($_POST['course']); // required
    $shift = utf8_decode($_POST['shift']); // not required
    $time = utf8_decode($_POST['time']); // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$email)) {
    $error_message .= '<font color="red">The Email Address you entered does not appear to be valid.</font><br />';
  }

    //$string_exp = "/^[A-Za-z .'-]+$/";

  if(strlen($fullName) < 6) {
    $error_message .= '<font color="red">The Name you entered does not appear to be valid.</font><br />';
  }

  if(strlen($sex) < 2) {
    $error_message .= '<font color="red">The Sex you entered do not appear to be valid.</font><br />';
  }

    $telephone_exp = "/^[0-9 .'+]+$/";

  if(!preg_match($telephone_exp,$telephone)) {
    $error_message .= '<font color="red">The telephone you entered does not appear to be valid.</font><br />';
  }


  if(strlen($birthDate) < 6) {
    $error_message .= '<font color="red">The Dirth Date you entered do not appear to be valid.</font><br />';
  }

  if(strlen($course) < 2) {
    $error_message .= '<font color="red">The Course you entered do not appear to be valid.</font><br />';
  }

  if(strlen($shift) < 2) {
    $error_message .= '<font color="red">The Shift you entered do not appear to be valid.</font><br />';
  }
  if(strlen($time) < 2) {
    $error_message .= '<font color="red">The Time you entered do not appear to be valid.</font><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 .= "Name: ".clean_string($fullName)."\n";
    $email_message .= "Sex: ".clean_string($sex)."\n";
    $email_message .= "Email: ".clean_string($email)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Birth Date: ".clean_string($birthDate)."\n";
    $email_message .= "Course: ".clean_string($course)."\n";
    $email_message .= "Shift: ".clean_string($shift)."\n";
    $email_message .= "Time: ".clean_string($time)."\n";
    // $mail->SMTPSecure = 'smtp.orkidevilla.com.kh';
    // $mail->Host = "localhost";

 // Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers = "Content-type:text/html; charset=utf-8". "\r\n";

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();

$email -> CharSet = "utf-8";
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

<font color="green">Thank you for contacting us. We will be in touch with you very soon.</font>

<?php

}
?>

html表单发送邮件

<form class="form-horizontal" role="form"  action="?p=RegisterForm" method="POST" style="border: 1px solid #ccc; padding: 10px;">
                <h3 style="text-align: center; margin-bottom: 30px;"><strong>ទម្រង់បំពេញពាក្យ</strong></h3>
                <div class="form-group">
                    <label for="firstName" class="col-sm-3 control-label">គោត្ដនាម និងនាម</label>
                    <div class="col-sm-9">
                        <input type="text" name="fullName" id="fullName" placeholder="ឡាតាំង (គោត្ដនាម និងនាម)" class="form-control" required>
                    </div>
                </div>

                 <div class="form-group">
                    <label for="country" class="col-sm-3 control-label">ភេទ</label>
                    <div class="col-sm-9">
                        <select name="sex" id="sex" class="form-control">

                            <option>ស្រី : Female</option>
                            <option>ប្រុស : Male</option>

                        </select>
                    </div>
                </div><!-- /.form-group -->

                <div class="form-group">
                    <label for="email" class="col-sm-3 control-label">អ៊ីម៉ែល</label>
                    <div class="col-sm-9">
                        <input type="email" name="email" id="email" placeholder="អ៊ីម៉ែល" class="form-control" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="telephone" class="col-sm-3 control-label">លេខទូរស័ព្ទ </label>
                    <div class="col-sm-9">
                        <input type="text" name="telephone" id="telephone" placeholder="(+855 012 000 000)" class="form-control" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="birthDate" class="col-sm-3 control-label">ថ្ងៃខែឆ្នាំកំណើត</label>
                    <div class="col-sm-9">
                        <input type="date" name="birthDate" id="birthDate" class="form-control" placeholder="dd - mm - yyyy " required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="country" class="col-sm-3 control-label">មុខវិជ្ជា</label>
                    <div class="col-sm-9">
                        <select name="course" id="course" class="form-control" >
                            <?php
                              $course=mysql_query("SELECT * FROM course WHERE status=1 ");
                              while($rowcourse=mysql_fetch_array($course)){
                            ?>
                            <option><?php echo $rowcourse['title']; ?></option>
                          <?php } ?>
                        </select>
                    </div>
                </div> <!-- /.form-group -->

                <div class="form-group">
                    <label for="country" class="col-sm-3 control-label">វេនសិក្សា</label>
                    <div class="col-sm-9">
                        <select name="shift" id="shift" class="form-control">
                            <option>ថ្ងៃចន្ទ​ ដល់ ថ្ងៃព្រហស្បត្ដិ៍ : Monday - Thursday</option>       
                            <option>ថ្ងៃចន្ទ​ ដល់ ថ្ងៃសុក្រ : Monday - Friday</option>
                            <option>ថ្ងៃសៅរ៍​ ដល់ ថ្ងៃអាទិត្យ : Saturday - Sunday</option>
                            <option>ថ្ងៃអាទិត្យ : Sunday</option>

                        </select>
                    </div>
                </div><!-- /.form-group -->
                <div class="form-group">
                    <label for="country" class="col-sm-3 control-label">ម៉ោងសិក្សា</label>
                    <div class="col-sm-9">
                        <select name="time" id="time" class="form-control">

                                    <option>06:00 - 07:00 AM</option>
                                    <option>07:00 - 08:00 AM</option>
                                    <option>08:00 - 08:00 AM</option>
                                    <option>08:00 - 09:00 AM</option>
                                    <option>09:00 - 10:00 AM</option>
                                    <option>11:00 - 12:00 PM</option>
                                    <option>12:00 - 01:00 PM</option>
                                    <option>01:00 - 02:00 PM</option>
                                    <option>02:00 - 03:00 PM</option>
                                    <option>03:00 - 04:00 PM</option>
                                    <option>04:00 - 05:00 PM</option>
                                    <option>05:00 - 06:00 PM</option>                                    
                                    <option>06:00 - 07:00 PM</option>
                                    <option>07:00 - 08:00 PM</option>
                                    <option>08:00 - 10:00 AM</option>
                                    <option>02:00 - 04:00 PM</option>
                                    <option>04:00 - 06:00 PM</option>

                                </select>
                    </div>
                </div><!-- /.form-group -->

                <div class="form-group">
                    <div class="col-sm-9 col-sm-offset-3">
                        <button type="submit" name="submit" id="submit" class="btn btn-primary btn-block">ចុះឈ្មោះ</button>
                    </div>
                </div>
            </form>

1 个答案:

答案 0 :(得分:0)

尝试设置连接,如下一行

   $con->query("set NAMES utf8");
   $con->query("set CHARACETER SET utf8");

然后尝试再次发送电子邮件,应该没问题。