[英]PHP Mail - receiving wrong words on the mail server
When I try to send mail from a web page - on the mail.bg and abv.bg mail I receive letters like this:当我尝试从 web 页面发送邮件时 - 在 mail.bg 和 abv.bg 邮件上,我收到这样的信件:
РќРѕРІРѕ
where I must receive "Ново" What can I do so I can fix it - on gmail.com I receive the normal "Ново" and when I use echo - I also receive the normal "Ново", but on the mail.bg and abv.bg - I receive this strange words...is there something wrong with the encoding?我必须收到“Ново” 我该怎么做才能修复它 - 在 gmail.com 我收到正常的“Ново”,当我使用 echo 时 - 我也收到正常的“Ново”,但在 mail.bg 和 abv 上。 bg - 我收到这个奇怪的词...编码有问题吗?
<?php
header('Content-Type: text/html; charset=utf-8');
header('Content-Transfer-Encoding: base64');
$errors = '';
$myemail = 'example@mail.bg';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "$subject, $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
$headers .= 'Content-Type: text/plain; charset=utf-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: base64'. "\n\r\n";
mail($to, '=?utf-8?B?'.base64_encode($email_subject).'?=', $email_body, $headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
When I try to send mail from a web page - on the mail.bg and abv.bg mail I receive letters like this:当我尝试从 web 页面发送邮件时 - 在 mail.bg 和 abv.bg 邮件上,我收到这样的信件:
РќРѕРІРѕ
where I must receive "Ново" What can I do so I can fix it - on gmail.com I receive the normal "Ново" and when I use echo - I also receive the normal "Ново", but on the mail.bg and abv.bg - I receive this strange words...is there something wrong with the encoding?我必须收到“Ново” 我该怎么做才能修复它 - 在 gmail.com 我收到正常的“Ново”,当我使用 echo 时 - 我也收到正常的“Ново”,但在 mail.bg 和 abv 上。 bg - 我收到这个奇怪的词...编码有问题吗?
Your headers are specifying Content-Transfer-Encoding: base64
but you have not applied base64_encode
on your contents.您的标头指定
Content-Transfer-Encoding: base64
但您尚未对您的内容应用base64_encode
。 (in your case $email_body
) (在你的情况下
$email_body
)
On the other hand, please use \r\n
to separate respective header lines另一方面,请使用
\r\n
分隔相应的 header 行
Hence, change the block因此,改变块
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
$headers .= 'Content-Type: text/plain; charset=utf-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: base64'. "\n\r\n";
mail($to, '=?utf-8?B?'.base64_encode($email_subject).'?=', $email_body, $headers);
to到
$email_body=base64_encode($email_body);
$headers = "From: $myemail\r\n";
$headers .= "Reply-To: $email_address\r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: base64'. "\r\n";
mail($to, '=?utf-8?B?'.base64_encode($email_subject).'?=', $email_body, $headers);
Alternatively, remove Content-Transfer-Encoding: base64 specification
, like this:或者,删除
Content-Transfer-Encoding: base64 specification
,如下所示:
//$email_body=base64_encode($email_body);
$headers = "From: $myemail\r\n";
$headers .= "Reply-To: $email_address\r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8' . "\r\n";
//$headers .= 'Content-Transfer-Encoding: base64'. "\r\n";
mail($to, '=?utf-8?B?'.base64_encode($email_subject).'?=', $email_body, $headers);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.