droc60607 2013-11-15 08:55
浏览 43
已采纳

将Unicode UTF8添加到电子邮件中

Can anyone help me please how to add a utf-8 Unicode for these characters?

žýáťčšľľzŽŘ

Now the email looks like this

Dostali ste novú správu. Tu sú podrobnosti: Jméno: tár Tel.Äíslo: 4996611

<?php

$EmailFrom = "...";
$EmailTo = "mail@mail";
$Subject = "Zpráva s ";
$name = Trim(stripslashes($_POST['name'])); 
$phone = Trim(stripslashes($_POST['phone'])); 
$email = Trim(stripslashes($_POST['email'])); 
$message = Trim(stripslashes($_POST['message'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "
";
$Body .= "Tel: ";
$Body .= $phone;
$Body .= "
";
$Body .= "Email: ";
$Body .= $email;
$Body .= "
";
$Body .= "Message: ";
$Body .= $message;
$Body .= "
";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Thanks

  • 写回答

1条回答 默认 最新

  • dongpo8250 2013-11-16 08:13
    关注

    You've got two ambiguous parts of your script where character-sets aren't being considered. It's possible your form isn't sending UTF-8 or it's possible you're sending UTF-8 in your email but the client is expecting a different encoding.

    1. I assume you're using a form to post data. Ensure it's set to send UTF-8 from the browser. The strings will now be UTF-8 encoded.

      <form action="myform" accept-charset="UTF-8">
      
    2. You need to add character set and transfer encoding headers to the email header:

      $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>
      Content-Type: text/plain; charset=UTF-8
      Content-Transfer-Encoding: 8bit");
      

    BTW, a faster way to redirect the user is to set the Location header in the response. Use:

    header('Location: contactthanks.php')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?