Sending plain email with PHP is easy. The mail function handles all the messy protocol details behind the scenes. But if you want to send attachments, you will need to dig into an RFC, specifically RFC 1341. This RFC describes MIME, Multipurpose Internet Mail Extensions.
Sending a Tab-Delimited Excel File
There are several example implementations to be found on the Web. Check out David Sklar's networking section. html?section_id=10>. Most of these put functionality into a class and attempt to incorporate every aspect of the standard. Its contains code that sends email with multiple attachments using two simple functions. Use this example as a basis for learning the process, and expand its functionality if necessary
The mailAttachment function assembles the parts that make up a MIME message. These parts are sent in the fourth argument of the mail function, which is generally used for headers. In the case of a MIME message, this area is used for both headers and attachments. After sending the customary From headers, a MIME-Version header is sent. Unless there's onlyone attachment, a boundary string must be created. This is used to divide attachments from one another. We want to avoid using a boundary value that might appear in the message itself, so we use the uniqid function.
Each attachment is surrounded by the boundaries that always start with two dashes. The attachment itself is prepared by the makeAttachment function. Each attachment requires Content-Type and Content-Transfer-Encoding headers. The type of content depends on the attachment itself. If an image file is being sent, it might be image/jpg. These are the same codes discussed above with regard to the HTTP protocol. For the sake of simplicity, this function always encodes attachments using base64, which can turn binary files into 7-bit ASCII. This prevents them from being corrupted as they travel through the network. As you might imagine, text files don't require encoding, and complete implementations encode attachments based on content type.
It may be instructive to see the assembled message in full. Try sending yourself a message. On a UNIX operating system, you should be able to peek at the file itself inside /var/spool/mail before reading it, or perhaps inside ~/Mail/received afterward.
PHP Related Interview Questions
|PHP Interview Questions||MySQL Interview Questions|
|PHP+MySQL Interview Questions||Drupal Interview Questions|
|MYSQL DBA Interview Questions||PHP5 Interview Questions|
|WordPress Interview Questions||Joomla Interview Questions|
|CakePHP Interview Questions||CodeIgniter Interview Questions|
|PHP7 Interview Questions|
An Introduction To Php
Variables, Operators, And Expressions
Classes And Objects
I/o And Disk Access
Time, Date, And Configuration Functions
Parsing And String Evaluation
Sorting Searching And Random Numbers
Integration With Html
Efficiency And Debugging
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.