Det här är en del av en klass som jag använder för att skicka ut HTML mail.
function send($commaSeparatedToList, $from, $subject, $alternativeText, $htmlLink)
{
// function for get the HTML page.
$handle = fopen($htmlLink, "r");
while (!feof($handle))
{
$HTMLpart .= fgets($handle, 1024);
}
print_r($commaSeparatedToList);
// Gets all recipients and put them into an array. Don't forget to trim later on..
$recipients = explode ( ",", $commaSeparatedToList);
// Gets the subject and converts it to MIME
$subject = $subject;
// Set some headers
$headers = "From: " . $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/alternative;
boundary=\"=_3630a29c32d555292a26fdae8b0df6d7\"\r\n";
// the message is multipart.
$message = '
--=_3630a29c32d555292a26fdae8b0df6d7
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit
' . $this->mimeEncode($alternativeText) . '
--=_3630a29c32d555292a26fdae8b0df6d7
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable
' . $this->mimeEncode($HTMLpart) . '
--=_3630a29c32d555292a26fdae8b0df6d7--
';
for ($i=0; $i<count($recipients); $i++)
{
mail(trim($recipients[$i]), $subject, $message, $headers);
}
return 1;
}
function mimeEncode($msg)
{
$msg= str_replace("=","=3D",$msg);
$msg= str_replace("Å","=C5",$msg);
$msg= str_replace("å","=E5",$msg);
$msg= str_replace("Ä","=C4",$msg);
$msg= str_replace("ä","=E4",$msg);
$msg= str_replace("ö","=F6",$msg);
$msg= str_replace("Ö","=C6",$msg);
return $msg;
}
Koden är nog inte väldigt optimerad, men den funkar för mig.
// Nippe