Email attachment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wald

    #1

    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(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;
    }
    }

  • Wald

    #2
    Re: Email attachment

    Wald <arnout.standae rt@n-o_s-p-a-m.cit.kuleuven. ac.be> wrote:
    [color=blue]
    > 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.[/color]

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

    Thanks,
    Wald

    Comment

    • Jeffrey Silverman

      #3
      Re: Email attachment

      On Tue, 08 Jul 2003 14:58:17 +0000, Wald wrote:
      [color=blue]
      > Wald <arnout.standae rt@n-o_s-p-a-m.cit.kuleuven. ac.be> wrote:
      >[color=green]
      >> 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.[/color]
      >
      > Just to let you know guys, even the smallest of clues might help here!
      >
      > Thanks,
      > Wald[/color]

      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/

      Comment

      • Wald

        #4
        Re: Email attachment

        "Jeffrey Silverman" <jeffrey@jhu.ed u> wrote:
        [color=blue]
        > On Tue, 08 Jul 2003 14:58:17 +0000, Wald wrote:
        >[color=green]
        >> Wald <arnout.standae rt@n-o_s-p-a-m.cit.kuleuven. ac.be> wrote:[color=darkred]
        >>> 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.[/color][/color]
        >
        > Try copying the headers off the email that works. Copy them
        > *exactly*.
        >
        > Paste into PHP script.
        >
        > Test email.[/color]

        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

        Comment

        • Jeffrey Silverman

          #5
          Re: Email attachment

          On Wed, 09 Jul 2003 13:11:38 +0000, Wald wrote:
          <snip!>[color=blue]
          > 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[/color]

          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/

          Comment

          Working...