Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

After define the header breaks dont work anymore

after I define a PHP header with UTF-8 my breaks on $msg don’t work anymore.
Where is the problem? Is there another way to make breaks?

Thanks!

Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?php  

$username = $_POST['name'];
  $lastname = $_POST['lastname'];
$useremail = $_POST['mail'];
  $fon = $_POST['phone'];
$usermsg = $_POST['nachricht'];
$myemail = "Mail@XY";

$msg = "Antwort an: $useremail\n". "Name: $username $lastname \n". "Telefonnummer: $fon \n". "Nachricht: $usermsg";

$subject = "Neue Nachricht vom Kontaktformular";

$headers = 'Content-type: text/html; charset=utf-8'. "\r\n"
          .'From: ' . $myemail . "\r\n";

if(empty($username)||empty($useremail)||empty($usermsg)){
  header("location:index.html?error");
}

else{
  $to = "Mail@XY";
  mail($to, $subject, $msg, $headers);
} 

?>

>Solution :

It’s not the utf-8 which has caused this, it’s the text/html.

You’re telling the receiving mail client to parse and display the email as a HTML document. As you hopefully know, in HTML a line break is specified using the <br> tag. HTML rendering engines do not take any notice of \n or \r\n – these are only useful in plain-text documents.

This:

$msg = "Antwort an: $useremail<br>". "Name: $username $lastname <br>". "Telefonnummer: $fon <br>". "Nachricht: $usermsg";

should fix it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading