PHP mail of function usage and configuration methods
- 2020-12-13 18:51:41
- OfStack
configuration
A good workman must sharpen his tools before he does his work well. First, let's take windows as an example to illustrate how to configure the local mail under 1.
Download the attachment ES7en.zip
- Unzip to any path, modify sendmail.ini, and modify the following information as needed.
[sendmail]
smtp_server=smtp.qq.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=***@qq.com
auth_password=***
force_sender=***@qq.com
-php.ini
[mail function]
SMTP = smtp.qq.com
smtp_port = 25
sendmail_from = ***@qq.com
sendmail_path = "D:/sendmail/sendmail.exe -t -i"
mail.add_x_header = On
Note:
At present, the test only shows that qq has been successfully sent, and the unsuccessful 163 May be that it has a filtering system and can be successfully sent to gmail.
grammar
mail(to,subject,message,headers,parameters)
Definition and usage
The mail() function allows you to send E-mail directly from the script.
Returns true if the delivery of the message was successfully received, or false if not.
instructions
In messages specified by the message parameter, rows must be separated by 1 LF (\n). Each line cannot exceed 70 characters.
(under Windows) When PHP connects directly to the SMTP server, if a period is found at the beginning of line 1, it will be deleted. To avoid this problem, replace a single period with two periods.
<?php
$text = str_replace("\n.", "\n..", $text);
?>
Hints and comments
Note: You need to keep in mind that just because a mail delivery is accepted does not mean it reaches its intended destination.
The sample
Here is an example of an official HTML email.
<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// When sending HTML When E-mail, always set content-type
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
// More header
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>