Ciao a tutti ho questo codice:
Codice PHP:
$to = "mittente@email.it";
$from = "ricevente@email.it";
$subject = "Oggetto del messaggio";
$content_message = file_get_contents("html/corpo_mail.html");
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "biglietti.pdf";
// encode data (puts attachment in proper format)
$fd = fopen($new_path_array[0], "r");
$contents = fread($fd, filesize($new_path_array[0]));
$attachment =base64_encode($contents);
// main header (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$msg_mail="
prova</p>";
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message_mail.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
//$headers .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
// send message
if(mail($to, $subject,$msg_mail, $headers))
{
echo "mail inviata";
}
else
{
echo "problemi invio email";
}
La mail arriva regolarmente con il relativo allegato, ma non si visualizza il corpo html del messaggio che per prova ho inserito in $msg_mail.
Ho sbagliato qualcosa?
Grazie.