您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php:mail()函数使用及配置用法详解

2024/2/28 13:48:27发布22次查看
配置
工欲善其事,必先利其器。首先我们以windows下面为例进行说明,如何配置一下本地的mail。
下载附件 sendmail.zip
 -解压到任意路径,修改sendmail.ini,根据实际需要修改下面的信息。
[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
注意:
目前测试只是qq发送成功,163的不成功可能是他有过滤系统,可以成功发送给gmail。
语法
mail(to,subject,message,headers,parameters)
定义和用法
mail() 函数允许您从脚本中直接发送电子邮件。
如果邮件的投递被成功地接收,则返回 true,否则返回 false。
说明
在 message 参数规定的消息中,行之间必须以一个 lf(\n)分隔。每行不能超过 70 个字符。
(windows 下)当 php 直接连接到 smtp 服务器时,如果在一行开头发现一个句号,则会被删掉。要避免此问题,将单个句号替换成两个句号。
<?php $text = str_replace("\n.", "\n..", $text); ?>
提示和注释
注释:您需要紧记,邮件投递被接受,并不意味着邮件到达了计划的目的地。
示例
下面引用一个官方的发送html邮件的例子。
<?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); ?>
以上就是php:mail()函数使用及配置用法详解的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product