Configuration
If a worker wants to do his job well, he must first sharpen his tools. First, let's take Windows as an example to explain how to configure local mail.
Download attachment sendmail.zip
- Unzip to any path, modify sendmail.ini, and modify the following information according to actual needs.
[sendmail] smtp_server=smtp.qq.com smtp_port=25 error_log file=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:
The current test is only successful sending of qq. The failure of 163 may be that he has a filtering system and can successfully send to gmail.
Syntax
mail(to,subject,message,headers,parameters)
Definition and usage
mail() FunctionAllows you to send an email directly from a script.
Returns true if the mail delivery is successfully received, otherwise returns false.
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); ?>
Tips and Notes
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
The following quotesan official example of sending 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> "; // 当发送 HTML 电子邮件时,请始终设置 content-type $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=utf-8" . "\r\n"; // 更多报头 $headers .= 'From: <webmaster@example.com>' . "\r\n"; $headers .= 'Cc: myboss@example.com' . "\r\n"; mail($to,$subject,$message,$headers); ?>
The above is the detailed content of php: Detailed explanation of mail() function usage and configuration usage. For more information, please follow other related articles on the PHP Chinese website!