I have a website, and in the "Contact" section I have a form which users may fill in to contact me. The form is a simple form which action is a php page.
我有一个网站,在“联系方式”部分,我有一个表格,用户可以填写以便与我联系。表单是一个简单的表单,其中action是一个php页面。
The php code:
php代码:
$to = "email@domain.com";
$name=$_POST['name']; // sender name
$email=$_POST['email']; // sender email
$tel= $_POST['tel']; // sender tel
$subject=$_POST['subject']; // subject CHOSEN FROM DROPLIST, ALL TESTED
$text=$_POST['text']; // Message from sender
$text.="\n\nTel:".$tel; // Added to message to show me the telephone nr to the sender at bottom of message
$headers="MIME-Version: 1.0"."\n";
$headers.="Content-type: text/plain; charset=UTF-8"."\n";
$headers.="From: $name <$email>"."\n";
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $text, $headers, '-fno-reply@domain.com');
Could somebody please tell me why this works most of the time, but sometimes I receive email whith no text and the subject line showing
有人可以告诉我为什么这种情况大部分时间都有效,但有时我收到的电子邮件没有文字和主题行显示
=?UTF-8?B??=
I use outlook express, and I have read this System.Net.Mail and =?utf-8?B?XXXXX.... Headers but it didn't help.
我使用outlook express,我已经读过这个System.Net.Mail和=?utf-8?B?XXXXX ....标题但它没有帮助。
The problem is not in Outlook, because when I log in to the actual mailprogram where I fetch the POP3 emails from, the email looks the same.
问题不在Outlook中,因为当我登录到我从中获取POP3电子邮件的实际邮件程序时,电子邮件看起来是一样的。
When I right click in Outlook and chose "message source" then there is no "From" information.
当我右键单击Outlook并选择“消息源”时,没有“发件人”信息。
Ex, a good message should look like this:
例如,一条好消息应如下所示:
Subject: =?UTF-8?B?w5Z2cmlndA==?= MIME-Version: 1.0 Content-type: text/plain; charset=UTF-8 From: John Doe
However, the ones with problem looks like this:
但是,有问题的人看起来像这样:
Subject: =?UTF-8?B??= MIME-Version: 1.0 Content-type: text/plain; charset=UTF-8 From:
As if the information has been lost somewhere.
好像信息已经丢失了。
You should know also that I have a VPS, which I manage myself. I use postfix as an emailserver, if thats got anything to do with it. But then again, why does it work sometimes?
你也应该知道我有自己管理的VPS。我使用postfix作为电子邮件服务器,如果这与它有关。但话又说回来,为什么它有时会起作用?
Also another thing that I have noticed is that sometimes special characters are not shown correctly (by both Outlook and the webmail).
另外我注意到的另一件事是有时特殊字符没有正确显示(通过Outlook和Webmail)。
For instance, the name "Björkman" in swedish is shown like Björkman
, but again, only sometimes.
例如,瑞典语中的“Björkman”这个名字就像Björkman一样,但有时也是如此。
I hope anybody knows something about this problem, because it is very hard to track down for me atleast.
我希望有人知道这个问题,因为我至少很难找到我。
If you need more input let me know.
如果您需要更多输入,请告诉我。
1 个解决方案
#1
0
Looks like the form is posted with all fields left blank. There are bots crawling the net and submitting empty forms. Have you been able to reproduce this with actual form data?
看起来表单已发布,所有字段都留空。有机器人爬网并提交空表格。您是否能够使用实际表单数据重现这一点?
Additional hint: your code is open to email header injection - I can post any headers I want, separated by line breaks, in $_POST['name'] and your code will put it into the email headers. At least remove any line breaks from user data that will go into the header section.
附加提示:您的代码对电子邮件标题注入是开放的 - 我可以在$ _POST ['name']中发布我想要的任何标题,以换行符分隔,您的代码会将其放入电子邮件标题中。至少从将进入标题部分的用户数据中删除任何换行符。
#1
0
Looks like the form is posted with all fields left blank. There are bots crawling the net and submitting empty forms. Have you been able to reproduce this with actual form data?
看起来表单已发布,所有字段都留空。有机器人爬网并提交空表格。您是否能够使用实际表单数据重现这一点?
Additional hint: your code is open to email header injection - I can post any headers I want, separated by line breaks, in $_POST['name'] and your code will put it into the email headers. At least remove any line breaks from user data that will go into the header section.
附加提示:您的代码对电子邮件标题注入是开放的 - 我可以在$ _POST ['name']中发布我想要的任何标题,以换行符分隔,您的代码会将其放入电子邮件标题中。至少从将进入标题部分的用户数据中删除任何换行符。