PHP Send UTF-8 mail without PEAR::Mail PEAR::Mail_Mime

后端 未结 3 936
栀梦
栀梦 2021-01-15 12:09

I would like to be able to send e-mails with PHP mail() containing the 8-bit characters åäö. They will be used in the subject, the message and in the \"From:\"-header. How c

相关标签:
3条回答
  • 2021-01-15 12:26

    Use the swiftmailer library. http://swiftmailer.org/

    0 讨论(0)
  • 2021-01-15 12:32
    $headers = array('From' => $from,
        'To' => "<$to>",
        'Subject' => $subject);
    
    if ($is_html) {
        $headers['Content-type'] = "text/html; charset=UTF-8";
    } else {
        $headers['Content-type'] = "text/plain; charset=UTF-8";
    }
    

    This works for me

    0 讨论(0)
  • 2021-01-15 12:34

    Simplest solution if you don't mind encoding even words that don't need it is to put everything in a base64 RFC 2047 encoded-word:

    $subject= "=?utf-8?b?".base64_encode($subject)."?=";
    $body= "blah blah $utf8text blah";
    $headers= "MIME-Version: 1.0\r\n";
    $headers.= "From: =?utf-8?b?".base64_encode($fromname)."?= <$fromaddress>\r\n";
    $headers.= "Content-Type: text/plain;charset=utf-8";
    
    mail($toaddress, $subject, $body, $headers);
    
    0 讨论(0)
提交回复
热议问题