Php – Adding a non breaking space to a php email does not insert spaces

emailhtmlphpspace

I have this PHP code:

mail($email, $subject, 
  "Welcome to **!\n\n The password for your account is:\n $password", 
  $headers);

Adding &nbsp to the php email content does not insert spaces.

I want to put two spaces between the colon and $password. Is there a way to add spaces?

Best Solution

You can send the email as HTML which requires extra headers and actual HTML in your message body:

// Add extra headers to $headers
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

// Send mail as HTML
mail($email, $subject, 
  "<html><body>Welcome to **!<br><br> The password for your account is:<br> &nbsp;$password</body></html>", 
  $headers);