dongxing4643 2016-03-17 16:09
浏览 35

通过电子邮件发送的逗号分隔.text文件中的奇怪数据

I have a simple form, when data is submitted an email is sent with a .txt file attached. The .txt has the data submitted separated by commas.

When some input is such:

  • ínput

I get in the .txt file attached in the email:

  • Ãnput

This is my code:

$to = "hugorod@hugorod.es";
$from = "hugorodadmin@hugorod.es";
$subject = "Subject";
$message = "<p>Please see the attachment.</p>";
$separator = md5(time());
$eol = PHP_EOL;
$filename = date('d.m.y-H:i:s') . "_". $_POST['fName'] . "_" . $_POST['gName'] . ".txt";
$data = $_POST['fName'] . ',' . $_POST['gName'] ."
";
$attachment = chunk_split(base64_encode($data));
$headers  = "From: ".$from.$eol; 
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
mail($to, $subject, $body, $headers);

I show $data and its correct, I guess the problem is when variables are encoded.

  • 写回答

1条回答 默认 最新

  • doudun2212 2016-03-17 16:32
    关注

    You're using ISO-8859-1 encoding, try UTF8 instead.

    You can use utf8_encode() to encode text from ISO-8859-1 to UTF8 (PHP Manual utf8_encode)

    Alternatively, change the charset of your email.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥15 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)