Home >Backend Development >PHP Problem >What is the usage of php mail
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.
#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)
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); ?>
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); ?>
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!