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
--PHP-mixed-$randomHash
Content-Type: multipart/alternative; boundary="PHP-alt-$randomHash"
--PHP-alt-$randomHash
Content-Type: text/plain; charset="iso-8859-2"
Content-Transfer-Encoding: 7bit
$bodyText
--PHP-alt-$randomHash
Content-Type: text/html; charset="iso-8859-2"
Content-Transfer-Encoding: 7bit
$bodyHTML
--PHP-alt-$randomHash--
EOM;
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
(file_get_contents("$websiteRoot/tmp/$fullNo/$row[0]")));
$message .= <<< EOM
--PHP-mixed-$randomHash
Content-Type: application/octet-stream; name="$row[0]"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--PHP-mixed-$randomHash--
EOM;
}
$result->close();
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,
$logEntry);
}
}
return $mailSent;
}
No.
>
>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: ';
You need a \r\n delimiter between the Reply-To: and Bcc: headers. As you have
it here, $headers will contain
From:test@localhost
Reply-To: test@localhostBcc: <etc>
> foreach (explode(',', $recipients) as $bcc) {
> $headers .= $bcc . ',';
> }
This will leave a comma after the last Bcc: email address.
Haven't looked at the rest, but you need to fix those problems at least before
it's going to work.
No. We have better things to do than debug your code for you.
Have you tested the MTA using a conventional MUA?
If so, and it works as expected, try stripping your code down to the
minimum necessary to replicate the fault. If you still don't
understand why its not working, post again with the minimum code and
the corresponding log entries from your MTA.
C.