Problème d'encodage avec un formulaire POST
Posté : 20 avr. 2010, 19:14
Bonjour à tous j'ai un petit problème dans la réception des mails.
Le formulaire est en flash et envoi par l'intermédiaire d'un POST les informations.
Les accents et les apostrophes s'affichent en code.
Voici mon code si quelqu'un peux m'aider svp
Merci pour votr aide
Le formulaire est en flash et envoi par l'intermédiaire d'un POST les informations.
Les accents et les apostrophes s'affichent en code.
Voici mon code si quelqu'un peux m'aider svp
Merci pour votr aide
<?php
require_once('./init.php');
function sendMail($to, $fromaddress, $subject, $body, $attachments=false)
{
$eol="\r\n";
$mime_boundary=md5(time());
# Common Headers
$headers .= "From: ".$fromaddress.$eol;
$headers .= "Reply-To: ".$fromaddress.$eol;
$headers .= "Return-Path: ".$fromaddress.$eol;
$headers .= "Message-ID: <".time()."-".$fromaddress.">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
# Boundry for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol;
# Open the first part of the mail
$msg = "--".$mime_boundary.$eol;
$htmlalt_mime_boundary = $mime_boundary."_htmlalt";
$msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol.$eol;
# Text Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=utf-8".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= strip_tags(str_replace("<br>", "\n", substr($body, (strpos($body, "<body>")+6)))).$eol.$eol;
# HTML Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=utf-8".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= $body.$eol.$eol;
//close the html/plain text alternate portion
$msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol;
if ($attachments !== false && count($attachments['name']) > 0)
{
for ($i = 0; $i < count($attachments['name']); $i++) {
if (is_file($attachments["tmp_name"][$i]))
{
# File for Attachment
$handle = fopen($attachments["tmp_name"][$i], 'rb');
$f_contents = fread($handle, filesize($attachments["tmp_name"][$i]));
$f_contents = chunk_split(base64_encode($f_contents));
fclose($handle);
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: ".$attachments["type"][$i]."; name=\"".$attachments['name'][$i]."\"".$eol;
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Description: ".$attachments['name'][$i].$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$attachments['name'][$i]."\"".$eol.$eol;
$msg .= $f_contents.$eol.$eol;
}
}
}
$msg .= "--".$mime_boundary."--".$eol.$eol;
ini_set(sendmail_from, $fromaddress);
$mail_sent = mail($to, $subject, $msg, $headers);
ini_restore(sendmail_from);
return $mail_sent;
}
parse_str(trim(file_get_contents(DIR_ROOT.$_POST['pathForm'])), $out);
foreach ($out as $k=>$v) {
$out[$k] = urldecode($v);
}
$message = '';
for ($i = 1; $i <= 4; $i ++){
$message .= '<b>'.$out['field'.$i].'</b>: '.nl2br(Core::StrT($_POST['field'.$i])).'<br />';
}
sendMail($out['email'], 'contact.form@'.$_SERVER['SERVER_NAME'], 'Contact form', $message);