Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP line breaks don't seem to work

I have the following code that sends a message using the mail() function. Everything works fine except the line breaks at the end of each line don't seem to work. As you can see I am using " \r\n " hoping that this will give me a line break but it doesn't I have added <br> to get the break, but I would rather not use that in case someone doesn't have an HTML email client.

<?php
  $to = '[email protected]'; // Was a valid e-Mail address, see comment below
  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;

  $content = 'Name: '.$name."\r\n";
  $content .= 'Email: '.$email."\r\n";
  $content .= 'Subject: '.$subject."\r\n";
  $content .= 'Message: '.$message."\r\n";

  $headers  = 'MIME-Version: 1.0' ."\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' ."\r\n";

  // Additional headers
  $headers .= 'To: iVEC Help <[email protected]>'. "\r\n";
  $headers .= 'From: '.$name.' <'.$email.'>' . "\r\n";

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

?>

<p> You sent it ... good work buddy </p>
<p> <?php   '$name' ?> </p>
like image 887
Ankur Avatar asked Dec 05 '25 17:12

Ankur


1 Answers

You're sending it as HTML - change the content type to text/plain and it should work.

like image 122
Greg Avatar answered Dec 08 '25 10:12

Greg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!