Buonasera,
è la prima volta che scrivo su questo forum, è da giorni che provo a risolvere questo problema spulciando anche su altri forum senza successo.
In breve, ho creato un form che permette di inviare delle mail specificando il mittente, il destinatario, l'oggetto e il testo del messaggio. Ecco il codice della pagina che utilizza la funzione php mail:
<?php
$to_address = $_POST['to_address'];
$from_address = $_POST['from_address'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$boundary = '==MP_Bound_xyccr948x==';
$headers = array();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: multipart/alternative; boundary="' . $boundary . '"';
$headers[] = 'From: ' . $from_address;
$msg_body = 'This is a Multipart Message in MIME format.' . "\n";
$msg_body .= '--' . $boundary . "\n";
$msg_body .= 'Content-type: text/plain; charset="iso-8859-1"' . "\n";
$msg_body .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
$msg_body .= strip_tags($message) . "\n";
$msg_body .= '--' . $boundary . "\n";
$msg_body .= 'Content-type: text/html; charset="iso-8859-1"' . "\n";
$msg_body .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
$msg_body .= $message . "\n";
$msg_body .= '--' . $boundary . '--' . "\n";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mail Sent!</title>
</head>
<body>
<?php
$success = mail($to_address, $subject, $msg_body, join("\r\n", $headers));
if ($success)
{
echo '<h1>Congratulations!</h1>';
echo '
The following message has been sent:
';
echo 'To: ' . $to_address . '
';
echo 'From: ' . $from_address . '
';
echo 'Subject: ' . $subject . '
';
echo 'Message:</p>';
echo nl2br($message);
} else
{
echo '
There was an error sending your message.</p>';
}
?>
</body>
</html>
Ho provato ad inviare la mail a 4 indirizzi differenti, domini Libero, Alice, Hotmail, Virgilio.
Il testo della mail è:
<html>
<h1>Titolo</h1>
Testo</p>
</html>
e aprendo la posta sul browser ho notato che mentre su Hotmail e Virgilio il messaggio viene visualizzato correttamente formattato, su Libero e su Alice visualizzo tutta l'intestazione e il corpo del messaggio ovvero:
MIME-Version: 1.0
Content-type: multipart/alternative;
boundary="==MP_Bound_xyccr948x=="
From: mittente@dominio.com
Return-Path: mittente@dominio.com
Message-ID: <FBCMCL01B04iCSF3HvF0007cfe2@FBCMCL01B04.fbc.local >
X-OriginalArrivalTime: 05 Jan 2010 16:19:41.0646 (UTC) FILETIME=[E2AC5EE0:01CA8E22]
This is a Multipart Message in MIME format.
--==MP_Bound_xyccr948x==
Content-type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Titolo
Testo
--==MP_Bound_xyccr948x==
Content-type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<html>
<h1>Titolo</h1>
Testo</p>
</html>
--==MP_Bound_xyccr948x==--
Mi sembra strano che Libero ed Alice non accettino il formato MIME, ma magari mi sbaglio! Qualcuno sa come si può risolvere il problema? Grazie!