ciao a tutti,

sto utlilizzando questo script che funziona perfettamente se la mail è visualizzata con outlook:
Codice PHP:
<?php
//define the receiver of the email
$to 'youraddress@example.com';
//define the subject of the email
$subject 'Test email with attachment';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash md5(date('r'time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment chunk_split(base64_encode(file_get_contents('attachment.pdf')));
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash?> 
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash?>"

--PHP-alt-<?php echo $random_hash?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

--PHP-alt-<?php echo $random_hash?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>

--PHP-alt-<?php echo $random_hash?>--

--PHP-mixed-<?php echo $random_hash?> 
Content-Type: application/zip; name="attachment.pdf" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

<?php echo $attachment?>
--PHP-mixed-<?php echo $random_hash?>--

<?php
//copy current buffer contents into $message variable and delete current output buffer
$message ob_get_clean();
//send the email
$mail_sent = @mail$to$subject$message$headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent "Mail sent" "Mail failed";
?>

Se visualizzata in gmail, smtp4dev etc fa il display del codice nel corpo mail; ne incollo un pezzo per dar l'idea:

--PHP-mixed-1d439a35b67396f22a4f31438feac9d1 Content-Type: multipart/alternative; boundary="PHP-alt-1d439a35b67396f22a4f31438feac9d1" --PHP-alt-1d439a35b67396f22a4f31438feac9d1 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. --PHP-alt-1d439a35b67396f22a4f31438feac9d1 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!

This is something with HTML formatting.
--PHP-alt-1d439a35b67396f22a4f31438feac9d1-- --PHP-mixed- Content-Type: application/zip; name="attachment.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment UEsDBBQAAAAIALVMM0XRujCx3SgAANjOAAASAAAAQnV0dF9tb3 JlX2Zha2UucHNk7R0JYBTVdTYX JIRLoVK1uEao0pZk9sxRCJIDSDlLglYpbTfZTbLNZjfd3RCwCp 6trbYaYmwD1FJAueSIFrByqYBK ghXQiijxAJFEyDmz9zF9/8+1RxKygdprf5iZ/9/77/jvH+/N7J8hI2dBISEh2BQLhwKOfGIo5HGa /0ZGTsHcuDhcuOFmyb1E7E0TZwrXGIKAfwSuMxHXGfXWkhsuWHc bbR8fzHzmtbblP8a4CQg1beeU acuqNCUVOqu0WFemN05N6dx3KEWq105NuVs1l5xblasr18+6z6 wrvG9eUcl9FSWZ2pRp2UlTlmUt q6yq1Fk10mWVBqMla9nUFI3WVKzLgjwCp6VIcRVrxdSU6Qgh/dHcBdJck1knVaUqJpeQMplUrU6V KVVqtex7Ujkpk6eR8E89WabMUqmz5OlSLqVkJ8F5illbmrUwbw YnDkpTU8qt1qqstLSamprUGkWq yVyWJsvMzERs5PLJUGOyZbnRqlk22Wi5jWXC88nTWUrM+iqr3m SUorKm2FRtnZqSAnWExAmqKjdZ TZZyU5UgzmhJxS1NLTFVpgnoNFkqmcZK4QQJqKw5ujJNyfKCBU W5efoyncWanZuXO2PG9PS86Rm5 6Tn5ZCapSifT1dPzp88gVbkKZf6UtL6JexeRazKYzHNNWl22Ao jDwb1TFemWWedoluvMFgEvGilH U4ahYQiDHhutSmO26IqWV+mmpizUWUzV5hJdYPt7k4dlzdNU6r LNOo1WWgmjAbQNRw+EDdI9iE04
.. etc etc etc...

non ho familiarità con multipart/mixed MIME type, multipart/alternative MIME type... avete idea di dove potrebbe risiedere il problema ?

Grazie in anticipo

PS: a me eventualmente basterebbe inviasse un testo semplice (no HTML) con un allegato il cui tipo so in anticipo (pdf)

Nik