How to use PHP to send mail _php tutorials

Source: Internet
Author: User
Tags rfc
PHP's small program for sending mail is simple, but there are a few things to keep in mind. First on the code:

!--? php $to = "gonnsai@163.com"; $user = "Gonn"; $date = Date ("Y year M D Day"); $headers = ' mime-version:1.0 '. "RN"; $headers. = ' content-type:text/html; Charset=utf-8 '. "RN"; $headers. = "To: $to RN"; $headers. = "Cc:252211974@qq.com rn"; $headers. = ' from:gonnsai@163.com '.    "RN";  $subject = "Zhuhai Life Circle"; $subject = "=? UTF-8? B? ". Base64_encode ($subject). "?     ="; $content = ' Dear '. " $user ". ' :'.'  
'; $content. = '
'; $content. = "Thank you for registering in Zhuhai Life Circle, the Wonderful Life starts from Zhuhai Life circle!" ".'
'; $content. = "In Zhuhai Life Circle, you can:".
'; $content. = "Check the business situation in Zhuhai, convenient for you to live and play." ".'
'; $content. = "Learn more about the recent events in Zhuhai to enrich your life. ".'
'; $content. = "Browse news hotspots and expand your knowledge. ".'
'; $content. = '
'; $content. = "Zhuhai Life Circle--to build Zhuhai's largest merchant database and constantly strive. ".' Www.zhuhailife.net '. '
'; $content. = '
'; $content. = "Zhuhai Life Circle Team".
'; $content. = "$date". '
'; $result = Mail ($to, $subject, $content, $headers); if ($result) {echo ' message sent successfully! ';}? >

There are a few places to be aware of. If the above code is not $subject = "=? UTF-8? B? ". Base64_encode ($subject). "? ="; In this sentence, you will find that the title of the message is garbled, and the message body is correct. The message header needs to be preceded by the function Base64_encode (), which is to encode the data using MIME base64. The title string is pre-encoded type such as: =? UTF-8? B?.

There is also the type of message set to $headers = ' mime-version:1.0 '. "RN";.

Explanation of the wiki: Multipurpose Internet Mail Extensions (mime,multipurpose) is an Internet standard that expands e-mail standards to support non-ASCII characters, mail messages in a variety of formats, such as binary format attachments. This standard is defined in RFC 2045, RFC 2046, RFC 2047, RFC 2048, RFC 2049, and so on. RFC 2822, which is a transition from RFC 822, stipulates that e-mail standards do not allow the use of characters other than the 7-bit ASCII character set in mail messages. Because of this, some non-English character messages and binary files, images, sounds and other non-text messages cannot be transmitted in e-mail. MIME defines a symbolic method for representing a wide variety of data types. In addition, a MIME framework is used in the HTTP protocol used in the World Wide Web.

MIME is implemented by standardizing the fields of the header of an e-mail message, and the additional areas of these headers describe the content and organization of the new message type.

$headers. = ' content-type:text/html; Charset=utf-8 '. "RN"; When the type is HTML, the message body can use the HTML tag.

Several common types:

    • Text/plain (plain text)
    • text/html (HTML document)
    • Application/xhtml+xml (XHTML documentation)
    • Image/jpeg (JPEG image) "PHP: Image/pjpeg"
    • Image/gif (GIF image)
    • Image/png (PNG image) "PHP: Image/x-png"
    • Video/mpeg (MPEG animation)
    • Application/pdf (PDF document)
    • Application/msword (Microsoft Word file)
    • Application/octet-stream (arbitrary binary data)
    • Application/x-www-form-urlencoded (Form submitted using the Post method of HTTP)
    • Multipart/form-data (IBID., but mainly used when the form submission is accompanied by file upload)

In addition, subtype, which has not yet been accepted as a formal data type, can use an X-starting independent name (for example, Application/x-gzip). The intrinsic name of the vnd-can also be used (example: application/vnd.ms-excel).

Parameter can be used to specify additional information, and in more cases, charset parameters that specify the way text is encoded, such as Text/plain and text/htm. MIME has a default subtype based on type, and when the client cannot determine the subtype of the message, the message is treated as the default subtype. Text default is text/plain,application default is Application/octet-stream and multipart is considered multipart/mixed by default.

http://www.bkjia.com/PHPjc/752430.html www.bkjia.com true http://www.bkjia.com/PHPjc/752430.html techarticle PHP's small program for sending mail is simple, but there are a few things to keep in mind. Code First: Php $to = "gonnsai@163.com"; $user = "Gonn"; $date = Date ("Y year M D Day"); $headers = ' MIM ...

  • 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.