mail()将消息作为.txt文件发送

I'm pretty new to PHP so don't mind the @... was a quick fix for opening the script without errors

I'm currently working on a mail script and its working pretty well. Sadly it sends the text the user enters as a .txt file instead of plain text

Basically the form is stored in messenger_mailsend.php and the content of the Textarea gets to messenger_mailsend_controller.php by using $_POST[].

    @$inhalt = $_POST['inhalt'];
    $message = strip_tags($inhalt);

    if(isset($_POST['submit'])){
    @mail($mailto, $subject, 'why not zoidberg?', $headers); 
    echo 'The mail was sent!';
    }

'why not zoidberg' is the test text i used to check if theres sth wrong with the var, actually it says mail($mailto, $subject, $message, $headers);

is the code I use to get the typed message from the form, remove the tags and store it as $message.

If I do a var_dump it says 'I am content' (what was typed in the form).. when the $message var is replaced by some plain text it still gets sent as TEXT.txt

The code i use for the $headers is:

    $headers .= 'From:' . $usrmail . "
";
$headers .= 'Reply-To:' . $reply . "
";
$headers .= 'X-Mailer: PHP/' . phpversion() . "
";
$headers .= 'X-Sender-IP:' . $_SERVER['REMOTE_ADDR'] . "
";
$headers .= 'Content-type: text/html; charset=ISO-8859-1
';

$headers .= 'Cc: ' . $cc . "
";
$headers .= 'Bcc: ' . $bcc . "
";

-- Solution: By setting the content-type to text/plain it works, thanks anyone! --

Well how can you expect the mail to be sent as html when you are stripping all the html tags before sending....

However, if you want to send the html mail, you have to define the same in the headers before sending. See the snippet:

$to = 'bob@example.com';
$subject = 'Website Change Reqest';

$headers = "From: " . strip_tags($_POST['req-email']) . "
";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "
";
$headers .= "CC: susan@example.com
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";

@$inhalt = $_POST['inhalt'];
$message = strip_tags($inhalt);

And then you send the mail like this:

mail($to, $subject, $message, $headers);