html - How can I have PHP send Chinese characters in an email? -


i've scoured stackoverflow trying find answer none of answers provided similar questions have solved problem.

so have pretty basic form here, , want able accept chinese characters, , send data in email. (note: chinese characters appear on webpage no issue)

html:

<!doctype html> <html> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <head> <link href="tour.css" rel="stylesheet"> </head> <body>  <?php include('tour-form.php') ?>  <div class="form">       <div class="row">         <div class="container">                  <br>              <form class="form-horizontal" role="form" method="post" action="tour.html">                  <div class="form-group">                         <label for="name" class="col-xs-2 control-label">姓名</label>                         <div class="col-xs-10">                             <input type="text" class="form-control" id="name" name="name" placeholder="您叫?" value="<?php echo htmlspecialchars($_post['name']); ?>">                             <?php echo "<p class='text-danger'>$errname</p>";?>                         </div>                     </div>             </form>          </div>     </div> </div>  </body> </html> 

php:

    <?php     if (isset($_post["submit"])) {         $name = $_post['name'];          $to = 'email@website.com';          $subject = 'new form';          $body = "customer: $name\n";          // check if name has been entered         if (!$_post['name']) {             $errname = 'please enter name';         }     // if there no errors, send email if (!$errname) {     if (mail ($to, $subject, $body, $from)) {         $result='<div class="alert alert-success">form submitted!</div>';     } else {         $result='<div class="alert alert-danger">error!</div>';     } }     } ?> 

my code works enough send email, if put chinese characters in form field, in email come out weird symbols.

please help!!

you can use chinese language inside email body using this:

$headers = 'from: youremail@example.com' . "\r\n";  $headers .= "content-type: text/html; charset=utf-8"; // add header if (mail ($to, $subject, $body, $headers)) {     // stuff } else {     // stuff } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -