0

I am trying to put breaks on my mail script. Because now I receive all the information in just one line. I have searched for \r\n and stuff but that doesnt work :(

Anyone suggestions? Would be of real help. THnx!

<?php
if($_POST){
  $vorm = $_POST['vorm'];
  $rente = $_POST['rente'];
  $einde = $_POST['einde']; 
  $waarde = $_POST['waarde'];
  $leen = $_POST['leen'];
  $aanhef = $_POST['aanhef'];
  $voornaam = $_POST['voornaam'];
  $achternaam = $_POST['achternaam'];
  $postcode = $_POST['postcode'];
  $telefoon = $_POST['telefoon'];
  $email = $_POST['email'];
  $message = $_POST['form_msg'];

  mail("m.bosch@unit-ict.nl", "Hypotheek aanvraag", $vorm .$rente .$einde .$waarde .$leen .$aanhef .$voornaam .$achternaam .$postcode .$telefoon .$email .$message);
}
arkascha
  • 41,620
  • 7
  • 58
  • 90

2 Answers2

0

Certainly such line breaks will work in email messages. Most likely you applied them wrong somehow. Here is a working example:

<?php
// [...]
mail(
  "m.bosch@unit-ict.nl", 
  "Hypotheek aanvraag", 
  sprintf("vorm: %s\r\nrente: %s\r\neinde: %s\r\nwaarde: %s\r\nleen: %s\r\naanhef: %s\r\nvoornaam: %s\r\nachternaam: %s\r\npostcode: %s\r\ntelefoon: %s\r\nemail: %s\r\n\r\nmessage:\r\n%s", 
  $vorm .$rente .$einde .$waarde .$leen .$aanhef .$voornaam .$achternaam .$postcode .$telefoon .$email .$message);
);

Also using heredoc notation would be a very elegant approach:

<?php
// [...]
$content = <<< EOT
vorm: {$vorm}

rente: {$rente}

einde: {$einde}

waarde: {$waarde}

leen: {$leen}

aanhef: {$aanhef}

voornaam: {$voornaam}

achternaam: {$achternaam}

postcode: {$postcode}

telefoon: {$telefoon}

email: {$email}

message: 

{$message}
EOT;

mail("m.bosch@unit-ict.nl", "Hypotheek aanvraag", $content);

Note that this will create an empty line between each line on most situation, but you are on the safe side like that. The issue here is that MS-Windows based systems (as often) do things different that defined in all standards.

arkascha
  • 41,620
  • 7
  • 58
  • 90
0

You could try the following:

<?php
$vorm = strip_tags( $_POST['vorm'] );
$rente = strip_tags( $_POST['rente'] );
$einde = strip_tags( $_POST['einde'] );
$waarde = strip_tags( $_POST['waarde'] );
$leen = strip_tags( $_POST['leen'] );
$aanhef = strip_tags( $_POST['aanhef'] );
$voornaam = strip_tags( $_POST['voornaam'] );
$achternaam = strip_tags( $_POST['achternaam'] );
$postcode = strip_tags( $_POST['postcode'] );
$telefoon = strip_tags( $_POST['telefoon'] );
$email = strip_tags( $_POST['email'] );
$message = strip_tags( $_POST['form_msg'] );

$naar = "m.bosch@unit-ict.nl";
$onderwerp = "Hypotheek aanvraag";

$bericht = 
"
Vorm: {$vorm}\r\n
Rente: {$rente}\r\n
Einde: {$einde}\r\n
Waarde: {$waarde}\r\n
Leen: {$leen}\r\n
Aanhef: {$aanhef}\r\n
Voornaam: {$voornaam}\r\n
Achternaam: {$achternaam}\r\n
Postcode: {$postcode}\r\n
Telefoon: {$telefoon}\r\n
Email: {$email}\r\n
Bericht: {$message}
";  

$headers = "From: yourname example@example.com";

mail($naar, $onderwerp, $bericht, $headers);

email() strip_tags() Prevent HTML tags from being send

SuperDJ
  • 7,488
  • 11
  • 40
  • 74
  • Which would give you one or two empty lines between all lines, depending of this code is executed on a MS-WIndows based system or, as more typical for a server, on a Linux based system. – arkascha Aug 20 '15 at 14:24
  • Well I have used this on multiple email forms and never had any problems – SuperDJ Aug 20 '15 at 14:28
  • This depends on what email client you use to read the email. Keep in mind that email is typically sent to different people, different people using different software. So "worked for me" is a questionable quality control :-) I prefer to take a look at standards and definitions and code valid messages. If then one client has a problem with the display, then that client has a bug because it violates standards or definitions. But indeed getting line breaks right in a plain text email is hard because of the well known MS-Windows annoyance. – arkascha Aug 20 '15 at 14:30