Send an email with an attachment in PHP _php tutorial

Source: Internet
Author: User
I often hear the question: "I have a contract from the website." How do I add an attachment to an e-mail message sent through a form? "The first thing I want to say is that there is no easy way to do this." You have a good understanding of PHP or other server-side scripting languages. And of course you want an account for a website that really supports PHP. If this is the case, you can send an email with an attachment in PHP after you've finished reading this chapter.

1. How the Attachment Works

If you've ever searched for an "attachment" function in the PHP manual, the result may be nothing (at least not at the time I wrote this article). Later you will spend a lot of time to understand this knowledge.

You might think that when you send an email with an attachment to someone, the attachment is placed in the recipient's mailbox with the message (for example, if you send him or her a PNG picture file, his/her mailbox will contain a TXT file (e-mail) and a. png file (attachment)). But that's not how it works. When you add an attachment, your mail program converts the attachment into a plain text file and inserts the text block after the content you write (the actual email). This, when you send everything out, the recipient's mailbox has only a plain text file-a file containing both the attachment and the actual email content.

Here is an example of an email with an attachment (an HTML file). I have highlighted several important lines:

Return-path:
Date:mon, May 2000 19:17:29 +0000
From:someone
To:person
Message-id: <83729KI93LI9214@example.com>
content-type:multipart/mixed; boundary= "396d983d6b89a"
Subject:here ' s The Subject

--396d983d6b89a
Content-type:text/plain; Charset=iso-8859-1
Content-transfer-encoding:8bit

This is the body of the email.

--396d983d6b89a
content-type:text/html; Name=attachment.html
Content-disposition:inline; Filename=attachment.html
Content-transfer-encoding:8bit



The attachment



http://www.bkjia.com/PHPjc/446863.html www.bkjia.com true http://www.bkjia.com/PHPjc/446863.html techarticle I often hear the question: "I have a contract from the website." How do I add an attachment to an e-mail message sent through a form? "The first thing I want to say is to do this ...

  • Related Article

    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.