Use php to send emails with attachments

Source: Internet
Author: User
I often hear this question: "I have a contract Sent from my website. How do I give
What if I add an attachment to an email sent through a form ?"
The first thing I want to talk about is that there is no simple way to do this. You must have a good understanding of PHP or other server-side scripting languages. Of course, you also need an account that truly supports PHP websites. If this premise is met, you can use PHP to send emails with attachments after reading this chapter.
1. How does the attachment work?
If you have searched for the "attachment" function in the PHP manual, there may be no results (at least I haven't written this article yet ). Later, you will spend a lot of time learning this knowledge.
You may want to put the attachment in the recipient's mailbox together with the email when you send an email with an attachment to someone (for example, if you send a PNG image file to him/her, his/her mailbox will contain a txt file (e-mail folder and a .png File (attachment ). But this is not how it works. When you add an attachment, your email program converts the attachment into a plain text file and inserts the text block after the content you write (the actual email. After you send all the items, the recipient's Mailbox contains only one plain text file-a file containing both attachments and actual email content.
The following is an example of an email with an attachment (an HTML file.
Return-Path:
Date: Mon, 22 May 2000 19:17:29 + 0000
From: Someone
To: Person
Message-id: <83729KI93LI9214@example.com>
Content-type: multipart/mixed; boundary = "mongod983d6b89a"
Subject: Here's the subject
-- Mongod983d6b89a
Content-type: text/plain; charset = iso-8859-1
Content-transfer-encoding: 8bit
This is the body of the email.
-- Mongod983d6b89a
Content-type: text/html; name‑attachment.html
Content-disposition: inline; filename=attachment.html
Content-transfer-encoding: 8bit
This is the attached HTML file
-- Mongod983d6b89a --
The first seven lines are the mail headers. Note the Content-type header section. This header tells the email program that the email is composed of more than one part. Emails without attachments only have one part: the message itself. Electronics with attachments usually consist of at least two parts: messages and attachments. In this way, an email with two attachments is composed of three parts: the message, the first attachment, and the second attachment.
Different parts of emails with attachments are separated by a line. The demarcation line is defined in the Content -- type header. Each new part of the email starts with two hyphens (--) and a line.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.