doushijiao0679 2010-12-23 15:31
浏览 248
已采纳

=?UTF-8?B ?? =通过php邮件发送的电子邮件问题

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.

The php code:

 $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.="

Tel:".$tel; // Added to message to show me the telephone nr to the sender at bottom of message

 $headers="MIME-Version: 1.0"."
";
 $headers.="Content-type: text/plain; charset=UTF-8"."
";
 $headers.="From: $name <$email>"."
";

 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.

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.

When I right click in Outlook and chose "message source" then there is no "From" information.

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?

Also another thing that I have noticed is that sometimes special characters are not shown correctly (by both Outlook and the webmail).

For instance, the name "Björkman" in swedish is shown like Björkman, but again, only sometimes.

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条回答 默认 最新

  • doumei2023 2010-12-23 16:24
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵