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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵