*/
function mailAttachment($to, $from, $subject,
$attachment)
{
//add from header
$headers = "From: $from\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//multiple parts require special treatment
if(count($attachment) > 1)
{
//multiple attachments require special
handling
$boundary = uniqid("COREPHP");
$headers .= "Content-Type: multipart/mixed";
$headers .= "; boundary =
$boundary\r\n\r\n";
$headers .= "This is a MIME encoded
message.\r\n\r\n";
$headers .= "--$boundary";
foreach($attachment as $a)
{
$headers .= "\r\n";
$headers .= makeAttachment($a);
$headers .= "--$boundary";
}
$headers .= "--\r\n";
}
else
{
$headers .= makeAttachment($attachment[0]);
}
//send message
mail($to, $subject, " ", $headers);
}
//add text explaining message
$attach[] = array("content"=>"This is Listing 18.6",
"type"=>"text/plain");
//add script to list of attachments
$fp = fopen(FILE, "r");