Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with mail attachments

S_p_ike
Guest
 
Posts: n/a
#1: Jul 17 '05
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 = "application/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_attachement ()
{
$this->xheaders["Content-Type"] = "multipart/mixed;\n
boundary=\"$this->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\nContent-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\nContent-type: $ctype;\n
name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition:
$disposition;\n filename=\"$basename\"\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
Guest
 
Posts: n/a
#2: Jul 17 '05

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 = "application/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_attachement ()
> {
> $this->xheaders["Content-Type"] = "multipart/mixed;\n
>boundary=\"$this->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\nContent-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\nContent-type: $ctype;\n
>name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition:
>$disposition;\n filename=\"$basename\"\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.sourceforge.net

--

\I/
/(@ @)\ Greetings from CyBy
---o00-(_)-00o--------------------
Manuel Lemos
Guest
 
Posts: n/a
#3: Jul 17 '05

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
http://www.meta-language.net/metastorage.html
Closed Thread