I was wondering how do I format my mail when I use PHP to send it. How do I add new lines, tab space, bold letters and words and so on?
2 Answers
You can add newlines, tabs, and spaces, by simply including newlines, tabs, and spaces in your message.
mail('[email protected]', 'A Message', "Hello,\nHow \t\t\t\t\t are you?\n\nSincerely, PHP.");
If you want to send a formatted message with bold, however, you'll have to format the message as HTML.
mail('[email protected]', 'A Message', "<html><head>...</head><body>Hello,<br /><strong>How</strong> are you?<br /><br />Sincerely, PHP.</body></html>");
Don't forget that whitespace like tabs and newlines don't really do anything in HTML (except provide a single space between words), so if you want whitespace in a formatted message you'll have to use HTML tags like <br /> and CSS properties like margin and padding.
Comments
you would use something like this
echo" This is my formated email \n and this is a new like. you can also use <br /><br />
";
1 Comment
VoteyDisciple
With single quotes,
\t and \n will not be treated as escaped characters. Strings with escape sequences need to be in double quotes.