Hi All,

While everybody is on this topic, here's a problem I have been having. I use
mail() in a function in a loop to send e-mail with an attachment. The
e-mails get sent out to the different recipients but only the last one gets
sent correctly. The rest loses the 'From:' somewhere so that the message
ends up with the server name as from who and with the encoded attachment
inside of the message body. Here's the function:

function mail_attachment ($to, $subject, $message, $addr_from, $attachment,
$filename) {

        /*
        This function sends an e-mail with a file attachment using the
standard
        PHP mail function with parameters $to, $subject and $message.
        The $attachment parameter is a string with the attachment file
content with
        filename $filename.
        */

        $boundary = "b".md5(uniqid(time()));
        $mime = "From: $addr_from\n";
        $mime .= "Reply-To: $addr_from\n";
        $mime .= "X-Mailer: Digital Healthcare Solutions\n";
        $mime .= "X-Sender: $addr_from\n";
        $mime .= "Content-type: multipart/mixed; ";
        $mime .= "boundary = $boundary\n\n";
        $mime .= "This is a MIME encoded message.\n\n";
        // First the regular message
        $mime .= "--$boundary\n";
        $mime .= "Content-type: text/plain\n";
        $mime .= "Content-Transfer-Encoding: base64";
        $mime .= "\n\n".chunk_split(base64_encode($message))."\n";
        // Now the attachment
        $mime .= "--$boundary\n";
        $mime .= "Content-type: text/plain\n";
        $mime .= "Content-Transfer-Encoding: base64\n";
        $mime .= "Content-Disposition: attachment; ";
        $mime .= "filename = ".chr(34).$filename.chr(34);
        $mime .= "\n\n".chunk_split(base64_encode($attachment))."\n";
        $mime .= "--$boundary--";

        mail ($to, $subject, "", $mime);
}

and here's the loop in which it gets called:

$i = 0;
while (isset($EmailAddress[$i])) {
        mail_attachment ($EmailAddress[$i], "URGENT Communication",
$message, $addr_from, $attachment, $filename);
        $i++;
}

Does anybody have any ideas?

Rudolf Visagie
Principal Software Developer
Digital Healthcare Solutions
Tel. +27(0)11 266 6946
Fax. +27(0)11 266 5080
Cell: +27(0)82 895 1598
E-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to