I've tested it with several options.
I've made an input field and tested it entering the following line:
rene<janssen>sman
This is the code I use to both send it to an email addres and displaying the resulting code:
<?php
$to = "mail@myemail.com";
$subject = "Sending a test mail";
$mijnnaam = ($_POST["tekst"]);
$message = "1. ".$mijnnaam."\r\n";
$message .= "2. ".htmlentities($mijnnaam)."\r\n";
$message .= "3. ".strip_tags($mijnnaam)."\r\n";
$message .= "4. ".htmlentities( strip_tags($mijnnaam))."\r\n";
$message .= "5. ". html_entity_decode (htmlentities($mijnnaam));
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
mail($to, $subject, $message, $headers);
echo $message;
?>
What I get in my mail is this:
- rene<janssen>sman
- rene<janssen>sman
- renesman
- renesman
- rene<janssen>sman
What is displayed in a browser window so I can see the html is this:
1. Rene<Janssen>Sman
2. Rene<Janssen>Sman
3. ReneSman
4. ReneSman
5. Rene<Janssen>Sman
To make my php script secure against attacking scripts is to input:
Rene<Janssen>Sman
having the inputted line filtered from html tags which could form such a script, e.g. with htmlentities so that it becomes:
Rene<Janssen>Sman
arriving as a plain/test email as:
Rene<Janssen>Sman
(so no html tags are present)
but displaying in the message part of the plain/text email as:
Rene<Janssen>Sman
Is such a thing possible? I did send myself an html mail. When I looked in my webmail and went for "show mail as plain text mail", it did show the line without those codes and surely my email provider has protected emailing against bad scripts somehow? Or am I thinking wrong?