Problem sendig e-mail attachments.

94 views
Skip to first unread message

Nuno Grenhas

unread,
Jun 14, 2007, 10:58:19 AM6/14/07
to mimemessage-dev
Summarizing the problem with file attachments:

- Small files are uploaded and sent with the message with no errors;

- Files with more than 1MB are sent with the message but shows the
error: "it was not
possible to read line from the SMTP server: data access time
out" (from the smtp_class wich is integrated with smtp_message_class).
If I increase the var $data_timeout (in smtp.php) to 30, for example,
theres's no error message but it shows nothing when it should go back
to the same page.

- Files with more than 2 MB are not uploaded but the message is sent
with no errors shown.

php.ini configuration:
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

I'm still stuck on this. My smtp server allows much more than 2MB
attachments, so I don't know where is the problem. Help me ppl.

The code:

$email_message=new smtp_message_class;
$email_message=__HEADERS__
$email_message->AddQuotedPrintableHTMLPart($email_message-
>WrapText($msg));

// Sending with attachment
if (isset($_FILES['anexo']['tmp_name']) && $inserir == "1") {

$err_file_size = "";

// Testing file size
if ( $_FILES['anexo']['size'] > 2000000 ) {
$err_file_size = "Atention! Unable to send! The file is
bigger than 2MB.";
}

$anexo = basename($_FILES['anexo']['name']);

// Copy the file to another folder -- don't work without it ???
if (copy($_FILES['anexo']['tmp_name'],"../anexos/".$anexo)) {

$file_attachment = array(
"FileName"=>"../anexos/".$anexo,
"Content-Type"=>"automatic/name",
"Disposition"=>"attachment"
);

$email_message->AddFilePart($file_attachment);
}
}

// Validating file size
if ( !empty( $err_file_size ) ) {
$aviso = "Ficheiro a anexar.<br>" . $err_file_size;

} else {

$MsgResult=$email_message->Send();

for($recipient=0,Reset($email_message->invalid_recipients);
$recipient<count($email_message-
>invalid_recipients);Next($email_message->invalid_recipients),
$recipient++)
$aviso = "Invalid recipient: ".Key($email_message-
>invalid_recipients)." Error: ".$email_message-
>invalid_recipients[Key($email_message->invalid_recipients)]."\n";

if ( $MsgResult == "" ) {
$aviso = "<font color=\"#009900\">MESSAGE SENT.<br />";

// Deleting the file
if (file_exists("../anexos/".$anexo)) {
unlink("../anexos/".$anexo);
}

} else {
$aviso = "ERROR: UNABLE TO SEND THE MESSAGE!<br />$MsgResult<br />";
}
}

Hope it isn't confuse.

Regards,
Nuno

Message has been deleted

Nuno Grenhas

unread,
Jun 15, 2007, 11:27:18 AM6/15/07
to mimemessage-dev
Note: I'm using Win2000 with IIS.

Manuel Lemos

unread,
Jun 16, 2007, 1:45:44 AM6/16/07
to mimemes...@googlegroups.com
Hello,

on 06/15/2007 12:00 PM Nuno Grenhas said the following:


> - Files with more than 1MB are sent with the message but shows the
> error: "it was not
> possible to read line from the SMTP server: data access time
> out" (from the smtp_class wich is integrated with smtp_message_class).

This means there was a connection timeout to receive server response.

> If I increase the var $data_timeout (in smtp.php) to 30, for example,
> theres's no error message but it shows nothing when it should go back
> to the same page.

I think the server is taking more than that time to process your file
because it is large.


> I increased the var $data_timeout=30 in "smtp.php" and now it shows a
> blank browser window with no message and nothing else.

Maybe your are exceeding the PHP script time limit. Try adding
set_time_limit(0); before sending the message in your script.

--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

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

Nuno Grenhas

unread,
Jun 18, 2007, 9:32:52 AM6/18/07
to mimemessage-dev
It works.
But I had to also increase var $timeout=60 and var $data_timeout=60 in
smtp.php.
Now I just have the problem with 2MB (or more) attachments. Probably
I'm not verifying the size of the file in the right place in code.

Thanks Manuel.
Regards,
Nuno

Nuno Grenhas

unread,
Jun 18, 2007, 11:54:32 AM6/18/07
to mimemessage-dev
This works if I establish the limit to 1000000. I have
upload_max_filesize = 2M and I tried with 4M. post_max_size = 8M and
I'm using MAX_FILE_SIXE = 2000000 in hidden input before the file
input in the form.

code:
-------------------------------------------------------------------------------------------
if (copy($_FILES['file']['tmp_name'],"tmp/".$file)) {

$err_file_size = "";

// Testing file size
if ($_FILES['file']['size'] > 2000000) {
$err_file_size = "Atention! File is bigger than 2MB.";

} else {
$file_attachment = array(
"FileName"=>"tmp/".$file,


"Content-Type"=>"automatic/name",
"Disposition"=>"attachment"
);

$email_message->AddFilePart($file_attachment);
}
}
-------------------------------------------------------------------------------------------

I searched for more info on file uploads to see if someone had the
same problem but didn't find nothing.

Manuel Lemos

unread,
Jun 19, 2007, 4:23:48 PM6/19/07
to mimemes...@googlegroups.com
Hello,

on 06/18/2007 10:32 AM Nuno Grenhas said the following:


> It works.
> But I had to also increase var $timeout=60 and var $data_timeout=60 in
> smtp.php.
> Now I just have the problem with 2MB (or more) attachments. Probably
> I'm not verifying the size of the file in the right place in code.

Maybe you are exceeding the PHP memory limits. What happens? Does PHP
script abort?

Manuel Lemos

unread,
Jun 19, 2007, 4:25:58 PM6/19/07
to mimemes...@googlegroups.com
Hello,

on 06/18/2007 12:54 PM Nuno Grenhas said the following:

The PHP default memory limit is 8MB. If the script is exceeding that
limit, you need to change memory_limit in php.ini .

Nuno Grenhas

unread,
Jun 21, 2007, 6:10:39 AM6/21/07
to mimemessage-dev

Manuel Lemos escreveu:

> Hello,
>
> on 06/18/2007 10:32 AM Nuno Grenhas said the following:
> > It works.
> > But I had to also increase var $timeout=60 and var $data_timeout=60 in
> > smtp.php.
> > Now I just have the problem with 2MB (or more) attachments. Probably
> > I'm not verifying the size of the file in the right place in code.
>
> Maybe you are exceeding the PHP memory limits. What happens? Does PHP
> script abort?

No the script doesn't abort. It simply sends the e-mail message
without the attachment, returning the success message. I increased the
memory_limit to 16M but still happens the same. I can see that it
doesn't upload the file at all because it's too fast returning the
message.

Manuel Lemos

unread,
Jul 2, 2007, 9:15:53 PM7/2/07
to mimemes...@googlegroups.com
Hello,

on 06/21/2007 07:10 AM Nuno Grenhas said the following:

Sorry for the delay.

It is hard to tell without seeing a message that you are sending.

If something fails, the class just returns an error and does not send
the message. If the message is sent anyway, there is no error.

Can you please send the message to mle...@acm.org ?

Reply all
Reply to author
Forward
0 new messages