English 中文(简体)
Adding a non breaking space to a php email does not insert spaces
原标题:

I have this PHP code:

mail($email, $subject, 
  "Welcome to **!

 The password for your account is:
 $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?

最佳回答

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
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";

// 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);
问题回答

Add <html> and </html>: to indicate the message is HTML formatted. Then you can use &nbsp;

Use the nl2br function to convert newlines to <br/>s.

Also set the Content-Type by appending a header "Content-Type: text/html; charset=UTF-8".

If you don t want to use HTML: you can use the tab-character too, but not sure if Hotmail supports that eighter.

This really depends on what you are reading it in. The problem with Hotmail is that it sees it as plan text, but converts it to HTML most likely to display to you.

Look at example 4 on how to send html email using php.

If the e-mail s Content-Type is text/plain, then all spaces should be honored. Sounds like you re transmitting the e-mail message as text/html, which is why you would need the &nbsp to get the second space to show up.

Use the http://swiftmailer.org/ Class to do emailing with PHP. It s nice done and gives you a lot of nice features.

Try using wordwrap when sending the message, this should break up the email and fix the issue:

@mail($to, $subject, wordwrap($message), $headers);




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签