PHPmail()函数使用及配置方法
配置
工欲善其事,必先利其器。首先我们以windows下面为例进行说明,如何配置一下本地的mail。
[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
[mailfunction]
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()函数允许您从脚本中直接发送电子邮件。
如果邮件的投递被成功地接收,则返回true,否则返回false。
说明
在message参数规定的消息中,行之间必须以一个LF(\n)分隔。每行不能超过70个字符。
(Windows下)当PHP直接连接到SMTP服务器时,如果在一行开头发现一个句号,则会被删掉。要避免此问题,将单个句号替换成两个句号。
提示和注释 注释:您需要紧记,邮件投递被接受,并不意味着邮件到达了计划的目的地。 $message=" //当发送HTML电子邮件时,请始终设置content-type //更多报头 mail($to,$subject,$message,$headers);
<?php
$text=str_replace("\n.","\n..",$text);
?>
示例
下面引用一个官方的发送HTML邮件的例子。
<?php
$to="somebody@example.com,somebodyelse@example.com";
$subject="HTMLemail";
<html>
<head>
<title>HTMLemail</title>
</head>
<body>
<p>ThisemailcontainsHTMLTags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
$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";
?>相关文章