Home >Backend Development >PHP Tutorial >PHP mail, phpmail_PHP tutorial

PHP mail, phpmail_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:53:151014browse

PHP mail, phpmail

PHP allows you to send emails directly from scripts.

PHP mail() function

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

Grammar

mail(to,subject,message,headers,parameters)
Parameter Description
to Required. Specify email recipients.
subject Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters.
message Required. Define the message to be sent. LF (n) should be used to separate lines.
headers
参数 描述
to 必需。规定 email 接收者。
subject 必需。规定 email 的主题。注释:该参数不能包含任何新行字符。
message 必需。定义要发送的消息。应使用 LF (n) 来分隔各行。
headers

可选。规定附加的标题,比如 From、Cc 以及 Bcc。

应当使用 CRLF (rn) 分隔附加的标题。

parameters 可选。对邮件发送程序规定额外的参数。
Optional. Specifies additional headers such as From, Cc, and Bcc.

Additional headers should be separated using CRLF (rn).

parameters Optional. Specifies additional parameters for the mailer.
Note: PHP requires an installed and running mail system in order for the mail functions to be available. The program used is defined through configuration settings in the php.ini file. 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.
<?<span>php
</span><span>//</span><span> 何问起 hovertree.com</span>
<span>$to</span> = "hello@hovertree.net"<span>;
</span><span>$subject</span> = "Test mail"<span>;
</span><span>$message</span> = "Hello! This is a simple email message."<span>;
</span><span>$from</span> = "hello@hovertree.net"<span>;
</span><span>$headers</span> = "From: <span>$from</span>"<span>;
</span><span>mail</span>(<span>$to</span>,<span>$subject</span>,<span>$message</span>,<span>$headers</span><span>);
</span><span>echo</span> "Mail Sent."<span>;

</span>?>

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:

PHP Mail Form
<html>
<body>
<!-- 何问起 hovertree.com -->
<?<span>php
</span><span>if</span> (<span>isset</span>(<span>$_REQUEST</span>['email'<span>]))
</span><span>//</span><span>if "email" is filled out, send email</span>
<span>  {
  </span><span>//</span><span>send email</span>
  <span>$email</span> = <span>$_REQUEST</span>['email'<span>] ; 
  </span><span>$subject</span> = <span>$_REQUEST</span>['subject'<span>] ;
  </span><span>$message</span> = <span>$_REQUEST</span>['message'<span>] ;
  </span><span>mail</span>( "someone@example.com", "Subject: <span>$subject</span>",
  <span>$message</span>, "From: <span>$email</span>"<span> );
  </span><span>echo</span> "Thank you for using our mail form"<span>;
  }
</span><span>else</span>
<span>//</span><span>if "email" is not filled out, display the form</span>
<span>  {
  </span><span>echo</span> "<span><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='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form></span>"<span>;
  }
</span>?>

</body>
</html>

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

Explanation of examples:

1) Windows needs to configure the SMTP of IIS; Linux comes with the sendmail component, no setting is required, and it directly supports the mail function sending function

2) Declare various SMTP parameters in php.ini

3) Use of mail("receiving address", "email subject", "email content") function


Example 1: Configuring local SMTP server

Step one: php.ini settings:
SMTP = localhost
smtp_port = 25

sendmail_from=your setting value

Step two: You need to install the SMTP that comes with IIS. Right-click on the SMTP virtual server and make the following settings in the pop-up properties window:

Click the "Access" tab, then click "Relay", click "Add" in the pop-up window, and then select "Single Server" Computer", add the IP address as "127.0.0.1", then


The way back is confirmed.

Step 3:

0792c400f4e899c4affbcbbf2a8dfddd

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

http://www.bkjia.com/PHPjc/1125077.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1125077.htmlTechArticle
PHP mail, 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,heade...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn