How to use PHP to send e-mail

Source: Internet
Author: User
Tags configuration settings php mail form
The sending of PHP e-mails plays an important role in PHP, so this article will explain the basics and how to use them in detail.

PHP allows you to send e-mail directly from a script.

PHP Mail () function

The PHP Mail () function is used to send e-mail from a script.

Grammar

Mail (to,subject,message,headers,parameters)

Parameters:

to required. Specify email recipients.

Subject required. Specify the subject of email. Note: This parameter cannot contain any new line characters.

Message required. Defines the message to be sent. You should use LF (\ n) to separate the rows. Each line should be limited to 70 characters characters.

Headers is optional. Specify additional headings, such as from, Cc, and BCC. You should use CRLF (\ r \ n) to separate additional headings.

Parameters is optional. Specify additional parameters for the mail sender.

Note: PHP runs a mail function that requires an installed and running messaging system (such as: SendMail, Postfix, qmail, and so on). The program used is defined by the configuration settings in the php.ini file. Please read more in our PHP Mail reference manual.

PHP Simple e-mail

The simplest way to send an email via PHP is to send a text email.

In the following example, we first declare variables ($to, $subject, $message, $from, $headers), and then we use these variables in the mail () function to send an e-mail message:

<?php$to = "someone@example.com";         Mail Recipient $subject = "parameter mail";                Message title $message = "Hello! This is the content of the message. ";  Message body $from = "someonelse@example.com";   Mail Sender $headers = "From:". $from;         Header Message Settings mail ($to, $subject, $message, $headers); echo "Mail Sent";? >

PHP Mail Form

With PHP, you can create a feedback form on your site. The following instance sends a text message to the specified e-mail address:


Example Explanation:

First, check that the message entry box is filled in

If not filled out (for example, when the page is first accessed), Export the HTML form

If you have already filled out (after the form is filled out), send an e-mail from the form

When you fill out the form by clicking the Submit button, the page reload, you can see the message input is reset, and also show the message sent successfully messages

Note: This easy to send e-mail is not safe, in the next chapter of this tutorial, you will read more about the security implications of e-mail scripts, and we will show you how to verify user input to make it more secure.

This article explains in detail the PHP sends the mail the related knowledge, the more study material clear concerns PHP Chinese net to be able to watch.

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.