What is the usage of php mail

藏色散人
Release: 2023-03-12 18:46:01
Original
1863 people have browsed it

php mail is used to send emails directly from scripts. The syntax of this function is "mail(to,subject,message,headers,parameters)", where the parameter to represents the recipient of the email.

What is the usage of php mail

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

Usage of mail

The mail() function allows you to send an email directly from a script.

Returns true if the mail delivery is successfully received, otherwise returns false.

Syntax

mail(to,subject,message,headers,parameters)
Copy after login

Parameters

to Required. Specify the recipients of the message.

subject Required. Specifies the subject of the email. This parameter cannot contain any newline characters.

message Required. Specifies the message to be sent.

headers Required. Specifies additional headers such as From, Cc and Bcc.

parameters Required. Specifies additional parameters for the sendmail program.

Explanation

In the message specified by the message parameter, lines must be separated by an LF (\n). Each line cannot exceed 70 characters.

(Under Windows) When PHP connects directly to an SMTP server, if a period is found at the beginning of a line, it will be deleted. To avoid this problem, replace the single period with two periods.

<?php
$text = str_replace("\n.", "\n..", $text);
?>
Copy after login

Note: You need to keep in mind that just because a mail delivery is accepted, it does not mean that the mail has reached its intended destination.

Example

Send a simple email:

<?php
$txt = "First line of text\nSecond line of text";
// 如果一行大于 70 个字符,请使用 wordwrap()。
$txt = wordwrap($txt,70);
// 发送邮件
mail("somebody@example.com","My subject",$txt);
?>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the usage of php mail. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template