Mail Attachments of bigger size - Apache crashes
Posted: Wed Sep 18, 2002 6:31 am
Hi,
after a lot of trying (and cursing) I was able to generate an email with attachment. The code is as follows:
If I use a file with very small size (~1000 B) it works just fine. But if I use a bigger file (pdf) which is approximatelly 200 KB, it (Apache 1.3.26) crashes (giving a windows error with something like "could not execute read on memory 0x00ABCDEF1234"... or something like it). I am using PHP4.2.2 and Windows 2000 SP3.
Could someone please give me a hint? I guess that mail() just cannot handle a mime header of a huge size, but i hope there is a workaround. Thx.
after a lot of trying (and cursing) I was able to generate an email with attachment. The code is as follows:
Code: Select all
(...)
/* select mode - either mail the pdf file or view it */
switch($mode)
{
case "mail":
/* init some vars */
$filename = "abc_".$username.".pdf";
$filepath = "../../tmp/" . $filename;
$boundary = $boundary = strtoupper(md5(uniqid(time())));
/* init mail configuration */
ini_set("SMTP", "smtp.abc.de");
ini_set("smtp_port", 25);
/* echo out status */
echo "<b>Filename</b> ........ = " . $filename . "<br>";
echo "<b>Filepath</b> ........ = " . $filepath . "<br>";
echo "<b>Mime boundary</b> ... = " . $boundary . "<br>";
/* temp solution */
$mail_message = "f***ing test mail message";
$to = "abc@abc.de";
$subject = "one freaking subject";
$sender_name = "sender name";
$sender_mail = "abc@abc.de";
/* build mime header */
$mime = "From: "$sender_name" <$sender_mail>\r\n";
$mime .= "To: <$to>\r\n";
$mime .= "MIME-Version: 1.0\r\n";
$mime .= "Content-Type: multipart/mixed; boundary=" . $boundary . "\r\n\r\n" .
"Your mail system does not support MIME.\r\n";
$mime .= "--$boundary\r\n";
$mime .= "Content-Type: text/plain\r\n" .
"Content-Transfer-Encoding: 8bit\r\n";
$mime .= $mail_message;
$mime .= "\r\n--$boundary\r\n" .
"Content-Type: application/pdf; name="$filename"\r\n" .
"Content-Transfer-Encoding: base64\r\n" .
"Content-Disposition: attachment; filename="$filename"\r\n\r\n";
/* encode file */
$filecontent = chunk_split(base64_encode(fread($fh = fopen($filepath, "rb"), filesize($filepath))));
fclose($fh);
$mime .= $filecontent;
$mime .= "\r\n--$boundary--";
echo "<br><b>MIME header:</b><br><font color="#777777">\n\n";
echo $mime;
echo "\n\n</font>";
/* here it crashes in mail() */
if(@mail($to,$subject,"",$mime))
{
echo "<br><br><font color=green><b>Mail was sent successfully</b></font>";
}
else
{
echo "<br><br><font color=red><b>Unable to send eMail - mail() error</b></font>";
}
break;
case "view":
/* redirect user to file */
header("Location: ./../../tmp/abc_" . $username . ".pdf");
break;
}
(...)Could someone please give me a hint? I guess that mail() just cannot handle a mime header of a huge size, but i hope there is a workaround. Thx.