How to Create Plain Text & Mime Formatted Email With PHP
When sending emails, there are two different formats used: plain text and MIME format. MIME is short for Multipurpose Internet Mail Extensions. It is an encoding protocol that lets you send emails that are not just plain text emails but emails encoded in HTML or have attachments such as images, sounds and other documents. Email clients such as Outlook or Web-based services like Gmail or Yahoo, allow you to send MIME formatted email. With PHP knowledge and a PHP Web server, you can create your own mail sending script that can allow you to send MIME formatted mail.
Instructions
-
Create Plain Text Email With PHP
-
1
Open up Notepad.
-
2
Type your PHP code. To create an email via PHP, you will need to create variables to hold the message, the subject of the email, as well as the email sender and recipient. Use PHP's mail() function to create the email. The PHP code will look like this:
<?php
$to = "myfriend@mail.com";
$subject = "Hello Friend";
$message = "Hello! ";
$from = "me@mail.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
?>
-
-
3
Save it as a PHP file.
-
4
Upload the PHP file on your Web server. On your browser, access the PHP file to send the email.
Create Mime Formatted Email With PHP
-
5
Download the PHP Mailer script package.
-
6
Unzip the files and upload it to a directory on your website.
-
7
Open up Notepad and type in your PHP code. Include the PHP Mailer files by adding the following to your code:
include_once('class.phpmailer.php');
Finish up your code by providing variables for your message, subject, the sender and recipient email addresses.
-
8
Save it as a PHP file.
-
9
Upload your PHP file on the same directory where you placed the PHP Mailer files. Access the PHP file on your browser to execute the script.
-
1
References
Resources
- Photo Credit Just One Film/Stockbyte/Getty Images