Mail() - 带有utf-8和html标签的邮件正文

时间:2017-01-13 08:20:26

标签: php email utf-8 email-headers

下面的网站使用脚本联系表格。它发送2条消息 - 给我和填写表格的人。在第二封邮件中,我遇到像“ąźćęś”这样的字符问题....我想使用utf-8。我在标题中设置它,但它不起作用。我还需要在消息体html标签中使用。 代码有什么问题?

<?php
// Check for empty fields
if(empty($_POST['email'])       ||
   empty($_POST['phone'])       ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    echo "No arguments Provided!";
    return false;
   }

$email_address = $_POST['email'];
$phone = $_POST['phone'];

// Create the email and send the message
$to = 'me@test.com';
$email_subject = "Mail to you";
$email_body = "Hello\n\n"."Test\n\nEmail: $email_address\n\nPhone: $phone";
$headers = "From: test@test.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);

$to2 = "$email_address";
$email_subject2 = "=?UTF-8?B?".base64_encode("Thanks for you message")."?=";
$email_body2 = "Test mail ążźćęśó\n\nBest regards\nTester";
$headers2 .= "Content-Type: text/html; charset=UTF-8";  
$headers2 = 'From: Tester <test@test.com>' . "\r\n";
mail($to2,$email_subject2,$email_body2,$headers2);
return true;            
?>

0 个答案:

没有答案