PHP mail and phpmail

Source: Internet
Author: User
Tags configuration settings php mail form

PHP mail and phpmail

PHP allows you to send emails directly from scripts.

PHP mail () function

The PHP mail () function is used to send emails from scripts.

Syntax
mail(to,subject,message,headers,parameters)
Parameters Description
To Required. Specifies the email recipient.
Subject Required. Specifies the subject of the email. Note: This parameter cannot contain any new line characters.
Message Required. Defines the message to be sent. LF (\ n) should be used to separate the rows.
Headers

Optional. Specify additional titles, such as From, Cc, and Bcc.

CRLF (\ r \ n) should be used to separate additional titles.

Parameters Optional. Specify additional parameters for the email sending program.

Note: PHP requires an installed and running email system to make the email function available. The program used is defined through 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 an email via PHP is to send a text email.

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

<? Php // He asked hovertree.com $ to = "hello@hovertree.net"; $ subject = "Test mail"; $ message = "Hello! This is a simple email message. "; $ from =" hello@hovertree.net "; $ headers =" From: $ from "; mail ($ to, $ subject, $ message, $ headers); echo" Mail Sent. ";?>

 

PHP Mail Form

With PHP, you can create a feedback form on your site. The following example sends a text message to the specified email address:

<Html> <body> <! -- He asked hovertree.com --> <? Phpif (isset ($ _ REQUEST ['email ']) // if "email" is filled out, send email {// send email $ email = $ _ REQUEST ['email ']; $ subject = $ _ REQUEST ['subobject']; $ message = $ _ REQUEST ['message']; mail ("someone@example.com", "Subject: $ subject", $ message, "From: $ email "); echo "Thank you for using our mail form";} else // if "email" is not filled out, display the form {echo "<form method = 'post' action = 'mailfo Rm. php '> Email: <input name = 'email 'Type = 'text'/> <br/> Subject: <input name = 'object' type = 'text'/> <br/> Message: <br/> <textarea name = 'message' rows = '15' cols = '40'> </textarea> <br/> <input type = 'submit '/> </form> ";}?> </Body> 

 

Example:

1) for windows, you need to configure SMTP for IIS. For linux, you do not need to configure sendmail. The mail function sending function is directly supported.

2) Declare SMTP parameters in php. ini

3) use the mail ("Receiving address", "Email Subject", "email content") Function

 

Example 1: configure the local SMTP Server

Step 1: php. ini settings:
SMTP = localhost
Smtp_port = 25
Sendmail_from = Your Set Value
Step 2: Install the SMTP that comes with IIS. Right-click the SMTP virtual server and make the following settings in the pop-up Properties window:
Click the "access" tab, click "relay", click "add" in the pop-up window, select "single computer", add IP address as "127.0.0.1", and then

Are returned.

Step 3:
<? Php
Mail ("123456@qq.com", "Test mail function of PHP.", "hello world! Hovertree.com ");
?>

Recommended: http://www.cnblogs.com/roucheng/p/3528396.html

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.