Hello group,
I've got a script here that sends emails with an attachment to
an email address that is retrieved from an html form. The
email sending code is include below.
The problem: when sending the email to certain email servers,
the attachment section of the email gets removed and I end up
with an attachment of zero kb. Other servers do accept the
attachment as expected.
This might seem to be server-related, but when I send a
regular email with attachment (not with the php code) to the
problem servers, nothing irregular happens and the attachment
stays intact. So the problem must be with the email generating
code, but I don't seem to be able to isolate it...
Anyone who can shed a light on this?
Thanks in advance,
Wald
-- email sending code ---------------------------------------
function sendmsg($to, $subject, $msgtext, $from, $file, $type)
{
$fp = fopen($file,"rb ");
$fcontent = fread($fp ,filesize($file ));
fclose($fp);
$content = chunk_split(bas e64_encode($fco ntent));
$sep = strtoupper(md5( uniqid(time())) );
$name = basename($file) ;
$header = "From: $from\nReply-To: $from\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=$sep
\n";
$body .= "--$sep\n";
$body .= "Content-Type: text/plain\n";
$body .= "Content-Transfer-Encoding: 8bit\n\n";
$body .= "$msgtext\n ";
$body .= "--$sep\n";
$body .= "Content-Type: $type; name=\"$file\"\ n";
$body .= "Content-Transfer-Encoding: base64\n";
$body .= "Content-Disposition: attachment; filename=
\"$file
\"\n";
$body .= "$content\n ";
$body .= "--$sep--";
if (mail($to, $subject, $body, $header)) {
return true;
} else {
return false;
}
}
I've got a script here that sends emails with an attachment to
an email address that is retrieved from an html form. The
email sending code is include below.
The problem: when sending the email to certain email servers,
the attachment section of the email gets removed and I end up
with an attachment of zero kb. Other servers do accept the
attachment as expected.
This might seem to be server-related, but when I send a
regular email with attachment (not with the php code) to the
problem servers, nothing irregular happens and the attachment
stays intact. So the problem must be with the email generating
code, but I don't seem to be able to isolate it...
Anyone who can shed a light on this?
Thanks in advance,
Wald
-- email sending code ---------------------------------------
function sendmsg($to, $subject, $msgtext, $from, $file, $type)
{
$fp = fopen($file,"rb ");
$fcontent = fread($fp ,filesize($file ));
fclose($fp);
$content = chunk_split(bas e64_encode($fco ntent));
$sep = strtoupper(md5( uniqid(time())) );
$name = basename($file) ;
$header = "From: $from\nReply-To: $from\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=$sep
\n";
$body .= "--$sep\n";
$body .= "Content-Type: text/plain\n";
$body .= "Content-Transfer-Encoding: 8bit\n\n";
$body .= "$msgtext\n ";
$body .= "--$sep\n";
$body .= "Content-Type: $type; name=\"$file\"\ n";
$body .= "Content-Transfer-Encoding: base64\n";
$body .= "Content-Disposition: attachment; filename=
\"$file
\"\n";
$body .= "$content\n ";
$body .= "--$sep--";
if (mail($to, $subject, $body, $header)) {
return true;
} else {
return false;
}
}
Comment