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.