It is a good practice to send HTML and TXT version of bunk emails. Some people just do not like HTML emails but they should still be able to get your message. The data comes from form in this example. As you can see from the code there is a post request which has submitted the form data to this page. You would probably want to include this code into a separate function or just forward the user away (on very simple site) from this page after the email has been submitted using the php header function.
if(isset($_POST['send_email'])){
// In this case I am only sending the email to 2 people and their email addresses are coming from the form
// Most likely you would get and array of email address and not only two so in that case you would loop through them and pass them into comma separated string
$strEmail1 = $_POST['email1'];
$strEmail2 = $_POST['email2'];
// Yours Email
$strYourEmail = $_POST['your_email'];
// Your Name
$strYourName = $_POST['your_name'];
$strSubject = "Test email";
$strTo = "$strEmail1,$strEmail2";
// Define the content (body of the email)
$strNoticeText = "This is a multi-part message in MIME format.";
$strHtmlText = "<html><body style=\"background-color:#000; color:#fff; padding:20px;\"><p>My test HTML email</p></body></html>";
$strPlainText = "My test TXT email";
// Email details
$strSemiRand = md5(time());
$strMimeBoundary = "==MULTIPART_BOUNDARY_$strSemiRand";
$strMimeBoundaryHeader = chr(34) . $strMimeBoundary . chr(34);
// Be careful not to include any space at the beginning of the lines of the text bellow
$strBody = "$strNoticeText
--$strMimeBoundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
$strPlainText
--$strMimeBoundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
$strHtmlText
--$strMimeBoundary--";
if (@mail($strTo, $strSubject, $strBody,
"From: " . $strYourName . "\n" .
"MIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n" .
" boundary=" . $strMimeBoundaryHeader)){
echo "Email sent successfully";
}else{
echo "Error occurred ";
}
}