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

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags echo email e-mail example function html mail name

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

PHP Mail () function

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

Syntax Mail (to,subject,message,headers,parameters) parameter description to required. Specify the email recipient. Subject required. Specify the subject of email. Note: This parameter cannot contain any new line characters. Message required. Defines the message to send. You should use LF (n) to separate rows. Headers

Optional. Specify additional headings, such as from, Cc, and BCC.

You should use CRLF (RN) to separate additional headings.

parameters Optional. Specify additional parameters for the mail-sending program.

Note: PHP requires an installed and running mail system to make mail functions available. 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 easiest way to send e-mail through PHP is to send a text email.

In the following example, we first declare the 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"; $subject = "Test mail"; $message = "hello! This is a simple e-mail message. $from = "someonelse@example.com"; $headers = "From: $from"; Mail ($to, $subject, $message, $headers); echo "Mail Sent." ?> PHP Mail Form

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

<html> <body> <?php if (isset ($_request[' email '))//if "Email" is filled out, send email {//send Email $ email = $_request[' email ']; $subject = $_request[' subject ']; $message = $_request[' message ']; Mail ("someone@example.com", "Subject: $subject", $message, "from: $email"); echo "Thank you as using our mail form"; else//if "Email" is not filled out, display the form {echo "<form method= ' post ' action= ' mailform.php ' > Email: < Input name= ' email ' type= ' text '/><br/> Subject: <input name= ' Subject ' type= ' text '/><br message: <br/> <textarea name= ' message ' rows= ' cols= ' > </textarea><br/> <input ' Submit '/ > </form> "; ?> </body> </html> Example explanation: First, check whether the message input box is filled in if it is not filled out (for example, when the page is first accessed), the output HTML form if it has been filled in (after the form is filled in), send the message from the form when you click the Submit button, Reload the page to display the message that the message was sent successfully
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.