• PHP mail() turns text with special characters into attachments

    From Jeroen Belleman@21:1/5 to All on Wed Aug 31 13:56:03 2022
    I use the PHP mail() function to send emails to a special interest group.
    Some of these mails are in English, no problems, and some of them are in French. For the latter, the message body text gets turned into an
    attachment, and the mail body remains empty. Apparently, it's the
    presence of accented characters that triggers this.

    The problem appeared when we recently moved the site to a different host.
    Both the old and the new host are Linux machines, running PHP 5.4.16 and
    Apache 20120211.

    Any ideas as to how to prevent my French text from getting hidden away
    in an attachment?

    Thanks,
    Jeroen Belleman

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Wed Aug 31 14:53:38 2022
    Jeroen Belleman, 2022-08-31 13:56:

    I use the PHP mail() function to send emails to a special interest group. Some of these mails are in English, no problems, and some of them are in French. For the latter, the message body text gets turned into an
    attachment, and the mail body remains empty. Apparently, it's the
    presence of accented characters that triggers this.

    Why an attachement? Why not just adding the appropriate MIME headers
    about the encoding and sending the text as UTF-8 or ISO-8859-1 or to be
    safe using quoted-printable for the transport?

    Also see:

    <https://www.php.net/manual/en/function.quoted-printable-encode.php>

    The problem appeared when we recently moved the site to a different host. Both the old and the new host are Linux machines, running PHP 5.4.16 and Apache 20120211.

    The first release of PHP 5.4 is more than 10(!) years old that version
    is *way* outdated!

    You should not use that version at all. Before doing any problem
    analysis you should first upgrade your environment. Besides possible
    security problems also bugs may be present which got fixed in newer version.

    Please update to at least PHP 7.4 or 8.0 and make sure your code works
    with that version (there are some breaking changes in PHP 7/8 compared
    to 5):

    <https://www.php.net/supported-versions.php>

    Any ideas as to how to prevent my French text from getting hidden away
    in an attachment?

    As suggested above - do not use attachements but just add the text with
    an appropriate encoding. There is no need to use attachments just
    because you use 8-bit characters.

    You can also use PHPMailer to make this process easier (which of course
    also requires a decent PHP version):

    <https://github.com/PHPMailer/PHPMailer>




    --
    Arno Welzel
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeroen Belleman@21:1/5 to Arno Welzel on Wed Aug 31 15:58:54 2022
    On 2022-08-31 14:53, Arno Welzel wrote:
    Jeroen Belleman, 2022-08-31 13:56:

    I use the PHP mail() function to send emails to a special interest group.
    Some of these mails are in English, no problems, and some of them are in
    French. For the latter, the message body text gets turned into an
    attachment, and the mail body remains empty. Apparently, it's the
    presence of accented characters that triggers this.

    Why an attachement?[...]

    I realize my wording was ambiguous. I *don't* want the French text
    to become an attachment.

    I haven't yet worked out the right sequence of incantations, but at
    least you have given me a lead. Thanks.

    [...]

    Please update to at least PHP 7.4 or 8.0 and make sure your code works
    with that version (there are some breaking changes in PHP 7/8 compared
    to 5):

    That's outside my jurisdiction.

    Again, thanks.

    Jeroen Belleman

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=c3=b8j?=@21:1/5 to Jeroen Belleman on Wed Aug 31 19:54:40 2022
    On 8/31/2022 7:56 AM, Jeroen Belleman wrote:
    I use the PHP mail() function to send emails to a special interest group. Some of these mails are in English, no problems, and some of them are in French. For the latter, the message body text gets turned into an
    attachment, and the mail body remains empty. Apparently, it's the
    presence of accented characters that triggers this.

    The problem appeared when we recently moved the site to a different host. Both the old and the new host are Linux machines, running PHP 5.4.16 and Apache 20120211.

    Any ideas as to how to prevent my French text from getting hidden away
    in an attachment?

    Non-ASCII should be encoded. Both in headers and body.

    function header_encode($str) {
    return '=?ISO-8859-1?Q?' . qp_encode($str) . '?=';
    }
    function body_encode($str) {
    return qp_encode($str, true);
    }
    ...
    $headers = ... .
    "Content-Type: text/plain; charset=ISO-8859-1\r\n" .
    ... .
    "Content-Transfer-Encoding: quoted-printable";

    or something similar.

    Arne

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeroen Belleman@21:1/5 to All on Thu Sep 1 14:24:12 2022
    On 2022-09-01 01:54, Arne Vajhøj wrote:
    On 8/31/2022 7:56 AM, Jeroen Belleman wrote:
    I use the PHP mail() function to send emails to a special interest group.
    Some of these mails are in English, no problems, and some of them are in
    French. For the latter, the message body text gets turned into an
    attachment, and the mail body remains empty. Apparently, it's the
    presence of accented characters that triggers this.

    The problem appeared when we recently moved the site to a different host.
    Both the old and the new host are Linux machines, running PHP 5.4.16 and
    Apache 20120211.

    Any ideas as to how to prevent my French text from getting hidden away
    in an attachment?

    Non-ASCII should be encoded. Both in headers and body.

    function header_encode($str) {
    return '=?ISO-8859-1?Q?' . qp_encode($str) . '?=';
    }
    function body_encode($str) {
    return qp_encode($str, true);
    }
    ...
    $headers = ... .
    "Content-Type: text/plain; charset=ISO-8859-1\r\n" .
    ... .
    "Content-Transfer-Encoding: quoted-printable";

    or something similar.

    Thanks for your comments. I think I identified another problem
    though. None of the Content-* directives I put in the header at
    the sending end remain intact at the receiving end. Small wonder
    the mail client doesn't know what to do. Grumble.

    The sending end uses xmail rather than sendmail. I wonder if
    that may be an issue. I'm beginning to wonder if I'm not better
    off moving everything back to the old host.

    Never try to fix something that works...

    Jeroen Belleman

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Fri Sep 2 09:22:02 2022
    Jeroen Belleman, 2022-08-31 15:58:

    On 2022-08-31 14:53, Arno Welzel wrote:
    [...]
    Please update to at least PHP 7.4 or 8.0 and make sure your code works
    with that version (there are some breaking changes in PHP 7/8 compared
    to 5):

    That's outside my jurisdiction.

    Then tell that those people who are responsible for the hosting. Keeping outdated software running just because nobody wants to change anything
    is never a good advise. At some point the stuff gets so old that you
    literally need to throw it away and create a complete new solution.


    --
    Arno Welzel
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From He, who travels time to time@21:1/5 to All on Thu Sep 22 07:11:10 2022
    Hey... Want to talk? Call me.... My telephone number >>>>

    (+372) 56330687

    Jeroen Belleman kirjutas Kolmapäev, 31. august 2022 kl 14:56:15 UTC+3:
    I use the PHP mail() function to send emails to a special interest group. Some of these mails are in English, no problems, and some of them are in French. For the latter, the message body text gets turned into an attachment, and the mail body remains empty. Apparently, it's the
    presence of accented characters that triggers this.

    The problem appeared when we recently moved the site to a different host. Both the old and the new host are Linux machines, running PHP 5.4.16 and Apache 20120211.

    Any ideas as to how to prevent my French text from getting hidden away
    in an attachment?

    Thanks,
    Jeroen Belleman

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)