如何让我的php表单接受外语字符?

时间:2015-02-27 21:05:25

标签: php utf-8 outlook character

我创建了一个需要接受外来字符(如繁体中文和越南语)的php表单。这是我正在使用的代码:

<?php

$EmailFrom = "Tristar Registration Request";
$EmailTo = "sbehringer@parsec-corp.com";
$Subject = "Tristar Registration Request";
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Company = Trim(stripslashes($_POST['Company']));
$Address = Trim(stripslashes($_POST['Address']));
$Contact = Trim(stripslashes($_POST['Contact']));
$Message = Trim(stripslashes($_POST['Message'])); 
$headers .= 'To: Tristar <info@ghstag.com>' . "\r\n";

// 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 .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Contact: ";
$Body .= $Contact;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, $headers);

//convert invalid strings
$newstring = iconv('UTF-8', 'UTF-8/IGNORE', $Body);

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

当我向Gmail提交测试时,特殊字符没有问题,但当电子邮件通过Outlook时,它显得很乱。我错过了一些UTF-8编码,还是没有Outlook的特殊设置,我需要调整以接受外来字符。任何帮助都会很棒!

2 个答案:

答案 0 :(得分:0)

将“Content-Type:text / html; charset = utf-8”添加到您的电子邮件标题中。

答案 1 :(得分:0)

我建议使用例如&#34; Swiftmailer&#34;,否则你仍然会遇到(utf-8)邮件主题和许多其他邮件功能的问题。 :/