Sometimes you will want to make your email format look cool like big company's do by branding their logo, cool styling, and other enhanced style right into the email body. In this PHP exercise will demonstrate the code needed to send HTML formatted emails and plain text formatted emails using the PHP mail() function.
HTML Formatted Email Message Body
For smooth email design, company branding, images, links, and more being added to your emails that you send.

<?php
$to = "PUT_RECIPIENT_EMAIL_ADDRESS_HERE";
$subject = "PUT_SUBJECT_HERE";
$mail_body = '<html>
<body bgcolor="#573A28" topmargin="25">
Put HTML content here with variables from PHP if you like
Variable display Example: ' . $subject . '
</body>
</html>';
$headers = "From:youremail@yoursite.comrn";
$headers .= "Content-type: text/htmlrn";
mail($to, $subject, $mail_body, $headers);
?>
Plain Text Formatted Email Message Body
For simplicity and no images or HTML will be blocked from showing by default in the recipient's email checking application. As many of you know logos or pictures get blocked by default in some email software.

<?php
$to = "PUT_RECIPIENT_EMAIL_ADDRESS_HERE";
$subject = "PUT_SUBJECT_HERE";
$mail_body = "Put any text lines with PHP variables in them
Variable display Example: $subject
";
$headers = "From:youremail@yoursite.comrn";
$headers .= "Content-type: textrn";
mail($to, $subject, $mail_body, $headers);
?>
HOT TIPS YOU MUST READ
1. PHP variables from a user input form can be placed right in the message body using either method above.
2. If your $mail_body value is wrapped in single quotes(which is best for standard HTML strings), be sure to use the method I showed in the HTML format example above for displaying the variable's value correctly. I also showed how to display variable values in the Plain Text Format version so you can see that variables will display if wrapped in double quotes, without having to modify the variables to display.
3. All images or logo files you might have to be online you refer to them by full path. They will not show up if you do not refer to the full URL of the online image file on your server. Your CSS must be inline tag styling. You can use the style attribute on any tags in your HTML formatted email.
4. Many email checking applications are set to block images and such by default. But the user can choose to see the images and HTML format if they choose.