Adding a non breaking space to a php email does not insert spaces
I have this PHP code:
mail($email, $subject,
"Welcome to **!\n\n The password for your account is:\n $password",
$headers);
Adding   to the php email content d开发者_开发问答oes 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\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> $password</body></html>",
$headers);
Add <html>
and </html>
: to indicate the message is HTML formatted. Then you can use
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 \t
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   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);
精彩评论