Problem with mail attachments

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

    #1

    Problem with mail attachments

    Hi all,

    I have a problem with mail with attachments.
    To send e-mail with attachments from a form, I use Setec Astronomy's libmail
    class (v 1.4) (available here http://www.phpclasses.org/)

    Everything is ok but if I use a specific e-mail address (say address X) in
    the field To, the e-mail arrives without attachments. (even if I use two
    addresses for field To, of which one is address X, the mail to address X
    arrives without attachments, the other arrives with attachments)

    So I think that the problem concerns a 'strange' configuration of the mail
    server of address X.

    Here are the functions for attachments

    function Attach ($filepath, $mimetype = "", $disposition = "inline",
    $filename = "")
    {
    if (empty ($filepath))
    { return false; }

    if (empty ($mimetype))
    { $mimetype = "applicatio n/x-unknown-content-type"; }

    if (empty ($filename))
    { $filename = basename ($filepath); }

    $this->fattach[] = $filename;
    $this->aattach[] = $filepath;
    $this->actype[] = $mimetype;
    $this->adispo[] = $disposition;

    return true;
    }

    function _build_attachem ent ()
    {
    $this->xheaders["Content-Type"] = "multipart/mixed;\n
    boundary=\"$thi s->boundary\"";

    $this->fullBody = "This is a multi-part message in MIME
    format.\n--$this->boundary\n";
    $this->fullBody .= "Content-Type: text/plain;
    charset=$this->charset\nConte nt-Transfer-Encoding: $this->ctencoding\n\n " .
    $this->body ."\n";

    $sep = chr(13) . chr(10);

    $ata = array();
    $k = 0;

    for ($i = 0; $i < count( $this->aattach); $i++)
    {
    $filename = $this->aattach[$i];
    $basename = basename($this->fattach[$i]);
    $ctype = $this->actype[$i]; // content-type
    $disposition = $this->adispo[$i];

    if (!file_exists ($filename))
    { return false; }

    $subhdr = "--$this->boundary\nCont ent-type: $ctype;\n
    name=\"$basenam e\"\nContent-Transfer-Encoding: base64\nContent-Disposition:
    $disposition;\n filename=\"$bas ename\"\n";
    $ata[$k++] = $subhdr;

    $linesz = filesize ($filename) + 1;
    $fp = fopen ($filename, 'r');
    $ata[$k++] = chunk_split (base64_encode (fread ($fp, $linesz)));
    fclose ($fp);
    }
    $this->fullBody .= implode ($sep, $ata);
    }

    Any suggestion on how to solve this problem?

    Thank you,
    Paolo


  • CyBy

    #2
    Re: Problem with mail attachments

    On Mon, 01 Nov 2004 16:35:01 GMT, "S_p_ike"
    <s_p_ike[NOSPAM]@hotmail.com> wrote:
    [color=blue]
    >Hi all,
    >
    >I have a problem with mail with attachments.
    >To send e-mail with attachments from a form, I use Setec Astronomy's libmail
    >class (v 1.4) (available here http://www.phpclasses.org/)
    >
    >Everything is ok but if I use a specific e-mail address (say address X) in
    >the field To, the e-mail arrives without attachments. (even if I use two
    >addresses for field To, of which one is address X, the mail to address X
    >arrives without attachments, the other arrives with attachments)
    >
    >So I think that the problem concerns a 'strange' configuration of the mail
    >server of address X.
    >
    >Here are the functions for attachments
    >
    > function Attach ($filepath, $mimetype = "", $disposition = "inline",
    >$filename = "")
    > {
    > if (empty ($filepath))
    > { return false; }
    >
    > if (empty ($mimetype))
    > { $mimetype = "applicatio n/x-unknown-content-type"; }
    >
    > if (empty ($filename))
    > { $filename = basename ($filepath); }
    >
    > $this->fattach[] = $filename;
    > $this->aattach[] = $filepath;
    > $this->actype[] = $mimetype;
    > $this->adispo[] = $disposition;
    >
    > return true;
    > }
    >
    > function _build_attachem ent ()
    > {
    > $this->xheaders["Content-Type"] = "multipart/mixed;\n
    >boundary=\"$th is->boundary\"";
    >
    > $this->fullBody = "This is a multi-part message in MIME
    >format.\n--$this->boundary\n";
    > $this->fullBody .= "Content-Type: text/plain;
    >charset=$thi s->charset\nConte nt-Transfer-Encoding: $this->ctencoding\n\n " .
    >$this->body ."\n";
    >
    > $sep = chr(13) . chr(10);
    >
    > $ata = array();
    > $k = 0;
    >
    > for ($i = 0; $i < count( $this->aattach); $i++)
    > {
    > $filename = $this->aattach[$i];
    > $basename = basename($this->fattach[$i]);
    > $ctype = $this->actype[$i]; // content-type
    > $disposition = $this->adispo[$i];
    >
    > if (!file_exists ($filename))
    > { return false; }
    >
    > $subhdr = "--$this->boundary\nCont ent-type: $ctype;\n
    >name=\"$basena me\"\nContent-Transfer-Encoding: base64\nContent-Disposition:
    >$disposition;\ n filename=\"$bas ename\"\n";
    > $ata[$k++] = $subhdr;
    >
    > $linesz = filesize ($filename) + 1;
    > $fp = fopen ($filename, 'r');
    > $ata[$k++] = chunk_split (base64_encode (fread ($fp, $linesz)));
    > fclose ($fp);
    > }
    > $this->fullBody .= implode ($sep, $ata);
    > }
    >
    >Any suggestion on how to solve this problem?
    >
    >Thank you,
    >Paolo
    >[/color]

    Try this one: phpmailer.sourc eforge.net

    --

    \I/
    /(@ @)\ Greetings from CyBy
    ---o00-(_)-00o--------------------

    Comment

    • Manuel Lemos

      #3
      Re: Problem with mail attachments

      Hello,

      On 11/01/2004 02:35 PM, S_p_ike wrote:[color=blue]
      > I have a problem with mail with attachments.
      > To send e-mail with attachments from a form, I use Setec Astronomy's libmail
      > class (v 1.4) (available here http://www.phpclasses.org/)
      >
      > Everything is ok but if I use a specific e-mail address (say address X) in
      > the field To, the e-mail arrives without attachments. (even if I use two
      > addresses for field To, of which one is address X, the mail to address X
      > arrives without attachments, the other arrives with attachments)
      >
      > So I think that the problem concerns a 'strange' configuration of the mail
      > server of address X.
      >
      > Here are the functions for attachments[/color]

      The code that opens the attachment files does not perform error
      checking. Therefore, it is probably failing for some reason and the file
      is not really attached.

      You may want to try this other class that does error checking and will
      tell you about any problems so you do not wonder why the message did not
      come with attachments:

      http://www.phpclasses.org/mimemessage


      --

      Regards,
      Manuel Lemos

      PHP Classes - Free ready to use OOP components written in PHP
      http://www.phpclasses.org/

      PHP Reviews - Reviews of PHP books and other products
      http://www.phpclasses.org/reviews/

      Metastorage - Data object relational mapping layer generator

      Comment

      Working...