1

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

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.

Thanks

Community
  • 1
  • 1
  • Read the accepted answer of the question you show in your question. `your subject contains relatively many characters outside the ASCII range.` It means that your server _can't_ send mail with subject with some accent or/and special char. Did you try with a subject like "Hello world" ? – Shikiryu Dec 23 '10 at 11:41
  • As the question says, this happens only sometimes. The subject line is one amongst 5 options in a drop list, all works and are tested. I believe that is not the problem. This problem happens sometimes only. –  Dec 23 '10 at 11:46
  • 1
    you may also try asking this on serverfault, as it might have something to do with the email server – Quamis Dec 23 '10 at 12:02
  • Have you tried adding `accept-charset="utf-8"` as an attribute to the contact form? Have you been able to reproduce this yourself? If not, which browsers have you tried? If you have, what does `var_dump($_POST)` say? Could you perhaps add a hidden field with the visitor's user agent string to the form so you can see if specific browsers cause problems? – mercator Dec 23 '10 at 16:29
  • Be aware that even though the subject is chosen via a dropdown. This doesn't mean someone can submit the same POST variables without a value to the same php-page. – ontrack Nov 24 '16 at 13:37

1 Answers1

0

When looking at PHP mail(), I see another line breaking: shouldn't you use \r\n as line endings?

And that Björkman example looks very much like your mail is not recognized as UTF-8 encoded.

Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80