Character Encoding in Sending Email and PHP

前端 未结 2 954
离开以前
离开以前 2021-01-24 22:01

I have a simple contact page that sends email with contact data with code below. But I can not read any of them because the characters are not readable. Based on my website cont

相关标签:
2条回答
  • 2021-01-24 22:18

    try this

    $header = "From: <$EmailFrom> \r\n";
    $header .= "MIME-Version: 1.0 \r\n";
    $header .= "Content-Type: text/html;charset=utf-8";
    
    $success = mail($EmailTo, $Subject, $Body, $header );
    
    0 讨论(0)
  • 2021-01-24 22:36

    Don't go with your own solutions to compose and send email, you are likely to get it wrong. Use some email class, for example PHPMailer. There just set CharSet property:

    $mailer = new PHPMailer();
    $mailer->CharSet = 'utf-8';
    

    Or [swiftmailer][2], or Pear's Mail Mime

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