471,852 Members | 941 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

Email attachment

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(base64_encode($fcontent));
$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;
}
}

Jul 16 '05 #1
4 26555
Wald <arnout.standaert@n-o_s-p-a-m.cit.kuleuven.ac.be> wrote:
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.


Just to let you know guys, even the smallest of clues might help
here!

Thanks,
Wald
Jul 16 '05 #2
On Tue, 08 Jul 2003 14:58:17 +0000, Wald wrote:
Wald <arnout.standaert@n-o_s-p-a-m.cit.kuleuven.ac.be> wrote:
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.


Just to let you know guys, even the smallest of clues might help here!

Thanks,
Wald


Try copying the headers off the email that works. Copy them *exactly*.

Paste into PHP script.

Test email.

later...
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Jul 16 '05 #3
"Jeffrey Silverman" <je*****@jhu.edu> wrote:
On Tue, 08 Jul 2003 14:58:17 +0000, Wald wrote:
Wald <arnout.standaert@n-o_s-p-a-m.cit.kuleuven.ac.be> wrote:
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.


Try copying the headers off the email that works. Copy them
*exactly*.

Paste into PHP script.

Test email.


Argh. This ended up being a problem with line endings. CRLF endings
are apparently needed after MIME separator lines, I only provided
one single \n.

Anyway, thanks for the moral support ;-)

Wald
Jul 16 '05 #4
On Wed, 09 Jul 2003 13:11:38 +0000, Wald wrote:
<snip!>
Argh. This ended up being a problem with line endings. CRLF endings are
apparently needed after MIME separator lines, I only provided one single
\n.

Anyway, thanks for the moral support ;-)

Wald


And thanks for describing what the problem turned out to be. Too many
threads end without reconciliation...
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Jul 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by abracad | last post: by
4 posts views Thread by Paul Schmidt | last post: by
5 posts views Thread by morphex | last post: by
3 posts views Thread by =?Utf-8?B?SHVnaA==?= | last post: by
7 posts views Thread by erikcw | last post: by
reply views Thread by tourerukcom | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.