Php Tutorial: Use the mail function to send attachments

Source: Internet
Author: User
After you build a website, you may think of regular backup or manual backup of databases and files for security purposes. In fact, we can store the database files and website-related files we need through our mailbox. The large capacity of the mailbox and the ability to store attachments determine that we can try to send database files and website files as attachments.

After you build a website, you may think of regular backup or manual backup of databases and files for security purposes. In fact, we can store the database files and website-related files we need through our mailbox. The large capacity of the mailbox and the ability to store attachments determine that we can try to send database files and website files as attachments.

After you build a website, you may think of regular backup or manual backup of databases and files for security purposes. In fact, we can store the database files and website-related files we need through our mailbox. The large capacity of the mailbox and the ability to store attachments determine that we can try to store database files and website files as attachments to the specified mailbox to complete the backup task. Let's take a look at how we can send emails with attachments through the mail component of php.

 '?.? "\ R \ n ";? ?? $ Headers ?. =? 'From :? '. $ From [0].'? <'. $ From [1].'> '?.? "\ R \ n ";? ?? // What is the main content of the email (HTML supported )?? $ Message? =? 'This is the information of an HTML Tag. He sent you the attachment you needed !! '. "\ N ".? ?? "-- {$ Mime_boundary} \ n "?.? ?? "Content-Type: text/html ;? Charset = \ "UTF-8 \" \ n "?.? ?? "Content-Transfer-Encoding :? 7bit \ n "?.? ?? $ Message ?.? "\ N ";? ?? // Configure the attachment :? ?? $ Name? =? 'Itluren.jpg ';? ?? //? The? Path? To? The? Image? With? The? File? Name :? ?? $ Fileatt? =? "Images/". $ name ;? ?? $ Fileatt_type? =? "Application/octet-stream ";? // File type ?? // Change the file name to the attachment name ?? $ Fileatt_name? =? $ Name ;?? ?? // Read related files? ?? $ File? =? Fopen ($ fileatt, 'rb ');? ?? $ Data? =? Fread ($ file, filesize ($ fileatt ));? ?? Fclose ($ file );?? ?? // What is the conversion size? ?? $ Data? =? Chunk_split (base64_encode ($ data ));?? // Add the attachment ?? $ Message ?. =? "-- {$ Mime_boundary} \ n "?.? ?? "Content-Type :? {$ Fileatt_type}; \ n "?.? ?? "? Name = \ "{$ fileatt_name} \" \ n "?.? ?? "Content-Transfer-Encoding :? Base64 \ n "?.? ?? $ Data ?.? "\ N "?.? ?? "-- {$ Mime_boundary} \ n ";? ?? Unset ($ data );? ?? Unset ($ file );? ?? Unset ($ fileatt );? ?? Unset ($ fileatt_type );? ?? Unset ($ fileatt_name );? ?? // Start sending birds ?? Mail ($ to [1],? $ Subject ,? $ Message ,? $ Headers );? ???> ??

If you are interested and want to make it more convenient, you can add a regular automatic transmission, and work with the creation of the compressed package and database backup files, we can let the website automatically complete the database and file backup.

Statement: This article uses BY-NC-SA protocol for authorization | IT passers-
Reprinted please note

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.