Questa sono le due funzioni che ho creato per inviare l'email
Codice PHP:
function inviaEmailNuovoIscrittoNewsletter($destinatario){
$boundary = "==========================================";
$header = "From: mittente <email_mittente>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/related;\n";
$header .= " boundary=\"$boundary\";\n\n";
$header .= " type=\"multipart/mixed\";\n";
$messaggio .= "--$boundary\n";
$messaggio .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$messaggio .= "Content-Transfer-Encoding: 7bit\n\n";
$messaggio .= "<html>\n";
$messaggio .= " <head>\n";
$messaggio .= " <style type=\"text/css\">\n";
$messaggio .= " blablabla\n";
$messaggio .= " </style>\n";
$messaggio .= " </head>\n";
$messaggio .= " <body bgcolor=\"white\">\n";
$messaggio .= " messaggio di prova\n";
$messaggio .= " <img src=\"cid:img1\">\n";
$messaggio .= " <img src=\"cid:img2\">\n";
$messaggio .= " </body>\n";
$messaggio .= "</html>\n";
$messaggio .= "--$boundary\n";
$messaggio .= allega('img1',$boundary);
$messaggio .= allega('img2',$boundary);
mail($destinatario,'Ti sei iscritto',$messaggio,$header);
}
Codice PHP:
function allega($nome,$boundary){
$messaggio = "Content-Type: image/gif\n";
$messaggio .= "Content-ID: <$nome>\n";
$messaggio .= "Content-Transfer-Encoding: base64\n\n";
$allegato = "../img/$nome.gif";
$file = fopen($allegato,'rb');
$data = fread($file,filesize($allegato));
fclose($file);
$data = chunk_split(base64_encode($data));
$messaggio .= "$data\n";
$messaggio .= "--$boundary\n";
return $messaggio;
}