gongzhonghao.png
扫码关注我们
最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

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

来源:http://erdangjiade.com/topic/2789.html 你好,世界。 2017-09-25 22:42浏览(110)

配置

工欲善其事,必先利其器。首先我们以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( )分隔。每行不能超过 70 个字符。
(Windows 下)当 PHP 直接连接到 SMTP 服务器时,如果在一行开头发现一个句号,则会被删掉。要避免此问题,将单个句号替换成两个句号。

<?php  
$text = str_replace("
.", "
..", $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" . "
";
$headers .= "Content-type:text/html;charset=utf-8" . "
";
// 更多报头
$headers .= 'From: <webmaster@example.com>' . "
";
$headers .= 'Cc: myboss@example.com' . "
";
mail($to,$subject,$message,$headers);
?>

以上就是php:mail()函数使用及配置用法详解的详细内容,更多请关注二当家的素材网其它相关文章!

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2