DevelopPHP
home gear home donate
Search Results For
in:

Libraries book

HTML Library CSS Library JavaScript Library PHP Library

Videosbook

PHP and MySQL JavaScript HTML and CSS Vector and 3D Flash Actionscript Android Dev Miscellaneous

Resourcesbook

Website Hosting Developer Q+A
Send PHP Email In HTML or Plain Text Format For More Design Options
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.

Learn HTML
<?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.

Learn HTML
<?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.


Home   •   Terms of Use   •   T-Shirts   •   RSS   •   Testimonials   •   Subscribe   •   Classroom Chalkboard   •   Developer Q+A   •   Donate   •   Top ↑
Popular In PHP / MySQL E-Commerce Store Production
Social Network Website Building
Image Upload / Photo Processing
CMS Software Programming
Mass Email Systems
Magic XML Data
Search Programming
Popular In JavaScript JSON Programming
Ajax Programming
Animating Elements
WYSIWYG Programming
Date/Time Programming
DOM Scripting
Object Reference
Popular In HTML Canvas Element
New Form Elements
Audio Element
Video Element
Drag and Drop
Event Handling
Element Grouping
Popular In CSS Custom Font Embedding
Dynamic Fit Backgrounds
Theatre Mode
Box Overlays
CSS Level 1 Properties
CSS Level 2 Properties
CSS Level 3 Properties
DevelopPHP.com is a growing educational system packed with video and written material that you can access 24/7 100% free. The focus here in 2014 is spread between five technologies: HTML, CSS, JavaScript, PHP and MySQL. Learn programming theory, database interaction, web design, animation, graphics editing, vector art, 3D modeling, and much more. The educational experience here is a hybrid one offering both high quality video tutorials and code libraries that grow more robust every day. The code libraries are being assembled so that developers can discover all of the building blocks of their favorite languages. The libraries coupled with high quality video tutorials will take you deep down the rabbit hole very quickly. You can also ask questions and get free advice at WebIntersect.com.
HTML5