Home  >  Article  >  Backend Development  >  Send email with attachments using PHP_PHP Tutorial

Send email with attachments using PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-15 13:23:181383browse

I often hear this question: "I have a contract sent from a website. How do I add an attachment to an email sent via a form?" The first thing I want to say is that there is no easy way to do this. You need a good understanding of PHP or other server-side scripting languages. Of course, you also need an account for a website that actually supports PHP. If you meet this prerequisite, you can use PHP to send emails with attachments after reading this chapter.

1. How attachments work

If you have ever searched for the "attachment" function in the PHP manual, the result may be nothing (at least as of this writing) time has not yet passed). 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 along with the email (for example, if you send him/her A PNG image file, his/her mailbox will contain a txt file (email) and a .png file (attachment)). But that's not how it works. When you add an attachment, your email program converts the attachment into a plain text file and inserts the block of text after what you wrote (the actual email). This, when you send everything out, there is only a plain text file in the recipient's inbox - a file that contains both the attachment and the actual email content.

Below is an example of an email with an attachment (an HTML file). I have marked some important lines:

Return-Path:
Date: Mon, 22 May 2000 19:17:29 +0000
From: Someone
To: Person
Message-id:
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



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446863.htmlTechArticleI often hear this question: "I have a contract sent from a website. How do I send it through the form? What about adding an attachment to an email you send? "First of all, I want to do this...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn