Domanda

Sto cercando di inviare un multipart / alternative e-mail MIME tramite script PHP ... tutto funziona benissimo, ma ho alcuni problemi con la codifica! I caratteri accentuati, nel corpo e-mail, vengono visualizzati erroneamente nel client di posta elettronica! Come può codificare il corpo per risolvere questo problema? ... Ho cercato di usare ..

utf8_encode($body)

Senza buoni risultati!

In un certo formato RAW e-mail, ho notato che le accentuazioni sono sostituite dalle = XX (dove xx sono char alfanumerico) ... Come posso fare questo?

Grazie in anticipo!

Questo è il codice:

$header = "From: \n";
$header .= "Reply-To: \n";
$header .= "Content-Type: multipart/alternative; boundary=$alt_boundary\n"; 
$header .= "Mime-Version: 1.0\n";
$header .= "X-Mailer: PHP/".phpversion()."\n";

$body .= "\n".wordwrap($txt_body, 70);

$body .= "\n\n--$alt_boundary\n";
$body .= "Content-Type: multipart/mixed; boundary=$mixed_boundary\n";

$body .= "\n\n\n--$mixed_boundary\n";
$body .= "Content-Type: text/html; charset=utf-8\n";
$body .= "Content-Transfer-Encoding: 7bit\n";

$body .= "\n".wordwrap($html_body, 70);

$body .= "\n\n\n--$mixed_boundary\n";   
$body .= "Content-Disposition: attachment filename=\"test file\"\n";
$body .= "Content-Type: application/octet-stream; x-unix-mode=0644; name=\test file\"\n";
$body .= "Content-Transfer-Encoding: 7bit\n";

$body .="\n$file";

$body .= "\n\n--$mixed_boundary--";
$body .= "\n\n--$alt_boundary--"; 

mail($to, $subject, $body, utf8_encode($header));

Modifica

Il $txt_body e $html_body sono i contenuti di due file:

$txt_body = file_get_contents(...);
$html_body = file_get_contents(...);

In questo file sostituisco alcune informazioni che ricevo da PayPal tramite IPN. Ho notato che quando ricevo l'e-mail, solo le accentuazioni che si verifica nel IPN informazioni vengono erroneamente visualizzati (in altre parole, le informazioni aggiuntive che sostituisco nei contenuti dei file)! Gli altri caratteri accentati vengono visualizzati correttamente !!

Come posso risolvere questo?

RISOLTO:

Ho risolto il problema! Funzione utf8_encode () deve essere applicato solo alle variabili informazioni papali, infatti, è che cerco di codificare in utf8 il $ txt_body ... le variabili paypal sono codificati 2 volte in utf8. In altre parole ho fatto che:

$txt_body = utf8_encode(file_get_contents(...));
$html_body = utf8_encode(file_get_contents(...));

e che in $ txt_body e $ html_body ho sostituito informazioni ricevuta tramite IPN!

Grazie alla ererybody!

È stato utile?

Soluzione

È necessario dichiarare la codifica dei caratteri che hai usato nell'intestazione di quella parte specifica:

MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=boundary

--boundary
Content-Type: text/plain; charset=utf-8

This part uses UTF-8.
--boundary
Content-Type: text/plain; charset=iso-8859-1

This part uses ISO 8859-1.
--boundary--

Altri suggerimenti

mail multistrato codifica UTF-8 possono essere facilmente create con SwiftMailer

$message->addPart($txt_body, 'text/plain', 'utf-8');
$message->addPart($html_body, 'text/html', 'utf-8');
$message->attach(Swift_Attachment::fromPath('/path/to/testfile'));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top