Topic: Emailing not setting mime-type

When I email an invoice using version 2.4.11 the mime type for the pdf document gets set as an unknown application. It may be the php version but the logic in class.email.inc is not working. It just runs right through to the line
return ‘application/unknown’;

Re: Emailing not setting mime-type

MIME Type is set in the device running the browser as it is used for rendering.
Maybe install Acrobat Distiller, SumatraPDF or have it set in a recent browser setting.

Re: Emailing not setting mime-type

I found a solution for the reporting/includes/class.mail.inc when I got the issue with the same thing.

I have found the solutions by changing all the \n code in the file to \r\n and it works on both PHP7.4 and PHP8.0

Emails are now sending and displaying correctly when sent from FA.

\r\n is for a new line in windows as for \n in the new line in Linux.

Use \r\n instead of \n for your implode -- explicitly specifies CRLF as the line terminator.

Wynand

Re: Emailing not setting mime-type

Ok. I’ll try that. I don’t think @apmuthu understood the question because the setting of the mime for sending an email attachment is absolutely done in the file you mentioned. I had been messing around with it and had forced it to set application/pdf for all attachments because it’s the only attachment I’ve ever sent. I’ll try your suggestion shortly.

Re: Emailing not setting mime-type

With the 2.4.17 this issue is still there. It seems that the reporting/includes/class.mail.inc is still not fixed. With every update the new file is overwritten and we are back to the same issue.

When I replace the core file with the change information as indicated below it will send the emails and attachments as expected.

"I have found the solutions by changing all the \n code in the file to \r\n and it works on both PHP7.4 and PHP8.0

Emails are now sending and displaying correctly when sent from FA.

\r\n is for a new line in windows as for \n in the new line in Linux.

Use \r\n instead of \n for your implode -- explicitly specifies CRLF as the line terminator."


Why are we keep on having the same issue irrespective of the PHP it is set on?

Is no one else have the same issue?

Wynand

Re: Emailing not setting mime-type

Just changed it and tested and now it mails to client and to admin in the copy to email address in company setup.

The standard class.mail.inc  sends nothing.

Replaced /n with /r/n and it works again.

Wynand

Re: Emailing not setting mime-type

This is what I receive in the email if I am lucky enough to get one without my changes to the file above:

--d6d94ed3a97c22d3af03070ba9b0c91c
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit

JVBERi0xLjMKMS4wMCB3CjMgMCBvYmoKPDwvVHlwZSAvUGFnZQovUGFyZW50IDEgMCBSCi9N
ZWRpYUJveCBbMCAwIDU5NS4yOCA4NDEuODldCi9SZXNvdXJjZXMgMiAwIFIKL0NvbnRlbnRz
IDQgMCBSPj4KZW5kb2JqCjQgMCBvYmoKPDwvRmlsdGVyIC9GbGF0ZURlY29kZSAvTGVuZ3Ro
IDE1MDU+PgpzdHJlYW0KeJzVWltT2zgUfs+vOC87284QV5IlX3hqIKGTTqEUvO3utn0QsQLe
+gKyDU1//Up2LnISCJ1p7OkwdpBzLH/nO1cpxhZC8AAI3qrjP/j8VX2E6nijjuveUQCvTjBg
oqWCKYyCHv7ZG5DlIQrm+eJNj1az9JjD9D+O5+mPpEeRMYx7cDl/nJqEIQLmWU2Cf3oSz8Xq
dh85+kwYyOu5NPMrxIxUU/Vxda8UMF17yFwuad5mPmRN3qUN+Xr4hDxzGvL18LlKEPQ8JWq5
pHnbE6BQU2m0Q2lMGkrMh6Z8g72tytIm3YuxIUJYc5LF2BCxWXOWxdgQoc4aFGdjlnXTN01V
z2ISuU1v6tOmRD02RdaN0ySzErkDTD2LqThSf/VDaGVk168GkwRejTEMM/hQRyJpROLikr0z
mrdEG2x1vDsd9aAmnuNwK3hBCJ9fDO7KKI45DML7KM9kDpPJy68QvFWPhQ/6FqxR/FgCww1g
W7AuLvm/FL7lUtY4y1ofYlvMrxRy/VqhYPA3jM8+vh8fj3Yp4q+hxvCLQSM1hXmWphEcx7K9
GvM4ncRlGKXXsDBHIHmUqgsrFfYPiNEloPP3cJR9B+ywNgFQsgTwhst8mqWFiNIDOJeiyGTE
DwAhSgxEldXsVq1moxVJN1kqHvOx/QHBaAMJ8mzHdRBluH04c15UGVugOeHfu2PFwIE8Bxhm    etc.




With the changes implemented as indicated above, a pdf copy is correctly received as an attachment to the email and a proper email.

Wynand

Re: Emailing not setting mime-type

As I can see, this fragment is not part of attachment, but for any reason pdf content was sent as email body, and marked as test/plain content type.
How the email was generated in FA?
J.

Re: Emailing not setting mime-type

That happens when I updated FA to 2.4.17. Email an invoice to a client and that is what the client receives.

Then I will replace the standard class.mail.inc with the the one I have changed as indicated. by changing all the \n code in the file to \r\n and it works on both PHP7.4, HP8.0, 8.1 and 8.2.

Then it sends the invoice correctly as a PDF attachment.

Wynand

Re: Emailing not setting mime-type

Seems this problem is Win php version related. This patch should fix two separate issues (the other one is bug reported in mantis 5711).
Thank you for reporting the problem.
J.

Re: Emailing not setting mime-type

@irronics, @joe: The said patch for reporting/includes/class.mail.inc will break for all versions of PHP < 5.4.
Refer the line:

var $headers = [];

It should be changed to:

var $headers = Array();

We need to take care of legacy users so as not to break their installs.

The PHP short array syntax does not work for older versions of PHP.

As of PHP 5.4 you can also use the short array syntax, which replaces array() with [].
https://stackoverflow.com/questions/40086788/short-array-syntax-in-php-5-6-doesnt-work

In fact there is a short array sniffer to check if needed but that is too bothersome.

Re: Emailing not setting mime-type

Good point. Fixed in additional commit.
Thank you.
J.

Re: Emailing not setting mime-type

Tnx

14 (edited by ckrosco 12/13/2023 11:57:28 pm)

Re: Emailing not setting mime-type

Thanks this patch is working for me.

But I am no longer getting a BCC as set in Setup -> Company Setup -> BCC Address for all outgoing mails

PHP 8.1 FA 2.4.17

With earlier versions I used to get BCC when emailing purchase orders.

Re: Emailing not setting mime-type

Some have success with PHP 8.0 and many have problems with later PHP versions.

Re: Emailing not setting mime-type

Some have success with PHP 8.0 and many have problems with later PHP versions.

Re: Emailing not setting mime-type

FA email is officially broken in PHP 8+ without mods, Gmail  and other mail server accounts are getting way stricter about delivery from mail(). We were getting client complaints. I think it's time to drop mail() and use phpmailer. The SMTP mail extension using phpmailer still works like a charm even in 8+ why not just include it in core? It is GNU LGPL 2.1

Re: Emailing not setting mime-type

I agree, it becomes an issue with more and more servers and client email servers.

I can set up my mail server to send emails in my Joomla Installation. Works better than via the current setup in FA.

I now save my invoices and send them via Outlook.

Wynand

Re: Emailing not setting mime-type

Have you tried the FA PHPMailer extension labeled "mail"? it works really good

here it is
https://github.com/apmuthu/FA24extensio … sions/mail

only drag is you have to replace "class.mail.inc" in core with the provided one to make it work. So it will break with updates. This is why I think it should become core even if as an option.

Re: Emailing not setting mime-type

@traficpest I installed the extension, took me a while but eventually got it.

It works great and just one issue, the old system have the attachment as the Invoice number, but on this mailer the attachment is just a long set of numbers.

Had a quick look at the code in class.mail.inc for both files:

Old File at line 68:

function attachment($file, $filename=null)
    {
        if (!isset($filename))
            $filename = basename($file);
        $this->attachment[$filename] = $file;
    }

New replacement file line 116:

public function attachment($file) {
        $this->phpmailer->addAttachment($file);
    }

How do we change that to use the invoice number instead of a long list of codes on the pdf attachment?

Wynand

Re: Emailing not setting mime-type

oh good catch! I didn't even notice that.

In the new file in the function pass the $filename then add the check if it is passed like the old version then pass it to 2nd argument in phpmailer addAttachement function. In the end the function should be this

public function attachment($file, $filename=null) {
  if (!isset($filename))
    $filename = basename($file);
  $this->phpmailer->addAttachment($file, $filename);
}

Re: Emailing not setting mime-type

Ok I pushed it to my fork in the mail branch of my repo and made a pull request for @apmuthu repo
you can find it here

https://github.com/trafficpest/FA24extensions/tree/mail

Re: Emailing not setting mime-type

Pulled in and updated Unofficial Extensions Repo.

Re: Emailing not setting mime-type

trafficpest wrote:

oh good catch! I didn't even notice that.

In the new file in the function pass the $filename then add the check if it is passed like the old version then pass it to 2nd argument in phpmailer addAttachement function. In the end the function should be this

public function attachment($file, $filename=null) {
  if (!isset($filename))
    $filename = basename($file);
  $this->phpmailer->addAttachment($file, $filename);
}

Changed it in my file and it works and display correctly now. Thanks @trafficpest.

Wynand

Re: Emailing not setting mime-type

apmuthu wrote:

Pulled in and updated Unofficial Extensions Repo.

@apmuthu does not seem to have pulled through. Re-downloaded the file from your link, but that file has not changed same error.

Wynand