UTF-8 encoding for subject in contact form email

后端 未结 2 1221
滥情空心
滥情空心 2020-12-03 15:39

On this sites Website Link contact form I need to send the subject for email in UTF-8. Where in the code we need to do declare the UTF-8 encoding?

kontakt.php:

相关标签:
2条回答
  • 2020-12-03 16:15

    here is how i did it:

    $head = "From: \"=?ISO-8859-15?Q?".imap_8bit("äöüßÄÖÜ sollte hier gehen")."?=\" <info@mydomain.de>\n";
    $subject = "=?ISO-8859-15?Q?".imap_8bit("äöüßÄÖÜ sollte hier gehen")."?=";
    mail($mail,$subject,$text,$head);
    

    that is ofc just Latin-15 (German) encoding. utf-8 works the same way: look here for a great explanation on how to use character encoding in mail headers: http://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/

    for your code you have to change this in the sendmail class:

    if (mail($this->to, '=?utf-8?B?'.base64_encode($this->subject).'?=', $this->body, $this->headers))
    

    ! this only works properly if your php file is utf-8 encoded !

    still very annoying. then i switched to phpmailer. that does everything for you. way more easy. i would suggest you use that.

    0 讨论(0)
  • 2020-12-03 16:20

    Or you can replace a $this->subject variable with

    $this->subject = '=?windows-1251?B?'.base64_encode($this->subject).'?=';

    Just replace

    windows-1251

    with some other encoding ( utf-8 or something else )

    0 讨论(0)
提交回复
热议问题