php电子邮件带有奇怪字符的字段

时间:2013-05-20 13:11:59

标签: php email character-encoding html-entities

我无法在PHP中使用我的代码向其姓名中包含特殊字符的人发送电子邮件,例如éàö。 以下是编码的片段:

$firstname = html_entity_decode(($row[firstname]), ENT_QUOTES | ENT_IGNORE, "UTF-8");
$lastname   = html_entity_decode(($row[lastname]), ENT_QUOTES | ENT_IGNORE, "UTF-8");
$tofirst    = html_entity_decode(($row[firstname]), "UTF-8");
$tolast = html_entity_decode(($row[firstname]), "UTF-8");

$to       = $tofirst .' '.$tolast .' <'. $email .'>';
$subject  = 'Your submission to the X-tension Dancebase';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Cc: dancers@x-tension.nl, chris@x-tension.nl' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";      
$headers .= 'From: X-tension Danceproductions <info@x-tension.nl>' . "\r\n" .
    'Reply-To: info@x-tension.nl' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();


if(mail($to, $subject, $message, $headers)) { 
  echo 'Successfully send an email to: '.$firstname.' '.$lastname.' <'.$email.'><br/>';
} else {
  if ((trim($email)) == "") {
    echo "Please fill out e-mail address and 'save profile' first";
  } else {
    echo 'error in mail script';    
  }
}

输入名称和电子邮件地址的页面的编码设置为UTF-8。 数据库的编码设置为UTF-8。 如您所见,电子邮件的标题设置为UTF-8。

我在保存名称的同时使用htmlentities选项尝试了它。 我在检索名称时使用html_entity_decode选项尝试了它,但没有。

该名称也在电子邮件的HTML正文中,并且在那里正确显示,但是当电子邮件未到达时,$ to变量中的名字和姓氏未出现,电子邮件到达或可能出现

非常感谢任何帮助。

Marijn

0 个答案:

没有答案