Wysyłanie maila w formacie HTML
mailashtml() wysyła tylko HTML, mailasmultipart() wysyła i plain-textem i w HTML, usiłując przez strip_tags() wygenerować sobie plain-text. To oczywiście nie zawsze wychodzi.define('SERWIS_NAME','Strona');
define('SERWIS_EMAIL_ADDRESS','nobody@egzample.tld');
define('SERWIS_EMAIL_ADDRESS_MAIL_HEADER_FROM','"'.SERWIS_NAME.'" <'.SERWIS_EMAIL_ADDRESS.'>');
$charset='iso-8859-2';
function mailashtml($email,$skrot,$message) {
global $charset;
$NL="\n";
$naglowki='From: '.SERWIS_EMAIL_ADDRESS_MAIL_HEADER_FROM.$NL.
'Reply-To: '.SERWIS_EMAIL_ADDRESS.$NL.
'MIME-Version: 1.0'.$NL.
'Content-Type: text/html; charset="'.$charset.'"'.$NL.
'Content-Transfer-Encoding: 8bit';
$skrot = '=?'.$charset.'?B?'.base64_encode($skrot).'?=';
mail($email,$skrot,$message,$naglowki);
}
function mailasmultipart($email,$skrot,$message) {
global $charset;
$NL="\n";
$mime_boundary = '----=_'.uniqid('');
$naglowki='From: '.SERWIS_EMAIL_ADDRESS_MAIL_HEADER_FROM.$NL.
'Reply-To: '.SERWIS_EMAIL_ADDRESS.$NL.
'MIME-Version: 1.0'.$NL.
'Content-Type: multipart/alternative; boundary="'.$mime_boundary.'"';
$skrot = '=?'.$charset.'?B?'.base64_encode($skrot).'?=';
$plain=strip_tags(str_replace(array('<br>','&','</p>','<p>'),array($NL,'&',$NL,''),$message));
$body='This is a multi-part message in MIME format.'.$NL.$NL.
'--'.$mime_boundary.$NL.
'Content-Type: text/plain; charset="'.$charset.'"'.$NL.
'Content-Transfer-Encoding: 8bit'.$NL.$NL.
$plain.$NL.$NL.
'--'.$mime_boundary.$NL.
'Content-Type: text/html; charset="'.$charset.'"'.$NL.
'Content-Transfer-Encoding: 8bit'.$NL.$NL.
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv="Content-Type content=text/html; charset='.$charset.'">
<style>
BODY {
font-family: Verdana;
font-size: 12px;
}
</style>
</HEAD>
<BODY>'.
$message.
'</BODY></HTML>'.$NL.$NL.
'--'.$mime_boundary.'--';
mail($email,$skrot,$body,$naglowki);
}
Data utworzenia : 2008-01-07