sending email with attachement with mail() and local mailserver

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I am learnimg PHP5. I am trying to send an email with attachment. I
decided to use mail() function with mailserver installed (Hamster in
WinXP) . The problem is that I don't receive email although is see in
Hamster's event log that it was sent. I would like to use mail()
function because I had problems with PHPMailer and PEAR.
I use the following function. BTW is this correct?

function sendEmail($recipients, $subject, $bodyText, $bodyHTML,
$fullNo, $withAttachment, $logEntry) {
    global $db, $websiteRoot;
        $randomHash = md5(date('r', time()));
        $headers = "From: test@localhost\r\nReply-To: test@localhost";
        $headers .= 'Bcc: ';
        foreach (explode(',', $recipients) as $bcc) {
            $headers .= $bcc . ',';
        $headers = rtrim($headers, ',');
        $headers .= "\r\n";
        $headers .= "\r\nContent-Type: multipart/alternative; boundary=
\"PHP-alt-" . $randomHash . "\"";
        if (!empty($fullNo)) {
                getYearMonthNo($fullNo, $year, $month, $no);
        $message = <<< EOM
Content-Type: multipart/alternative; boundary="PHP-alt-$randomHash"

Content-Type: text/plain; charset="iso-8859-2"
Content-Transfer-Encoding: 7bit


Content-Type: text/html; charset="iso-8859-2"
Content-Transfer-Encoding: 7bit



        if ($withAttachment) {
                $result = $db->query('SELECT file_name, picture FROM
pictures ' .
                                  "WHERE a_year = $year AND a_month = $month
AND a_no = $no");
                @mkdir($websiteRoot . '/tmp/' . $fullNo);
                while ($row = $result->fetch_row()) {
                        createPicture($websiteRoot . '/tmp', $fullNo,
$row[0], $row[1]);
                        $attachment = chunk_split(base64_encode
                        $message .= <<< EOM
Content-Type: application/octet-stream; name="$row[0]"
Content-Transfer-Encoding: base64
Content-Disposition: attachment


                removeDirectory($websiteRoot . '/tmp/' . $fullNo);
        $mailSent = @mail('', $subject, $message, $headers);
        if ($mailSent) {
                if (!empty($fullNo)) {
                        writeToLog(null, null, null, $year, $month,
$no, $logEntry);
                } else {
                        writeToLog(null, null, null, null, null, null,
        return $mailSent;

Site Timeline