您的位置:首页 > 编程语言 > PHP开发

在php 中使用mail函数

2015-10-11 20:06 633 查看
注:php环境配置完整,参考 http://www.cnblogs.com/homezzm/archive/2012/08/01/2618062.html
1.本地windows需安装SMTP服务器,建议使用Free SMTP Server,链接——http://www.softstack.com/freesmtp.html

2.安装完成后 查看自己的php配置文件,即php.in中是否有如下配置:

SMTP = localhost
; http://php.net/smtp-port smtp_port = 25

3.接下来演示代码,创建一个html表单输入,一个php文件进行处理,本地smtp服务器充当邮局向外发送。

(1)feedback.html

<form action="processfeedback.php" method="post" xmlns="http://www.w3.org/1999/html">
<br>Name</br>
<input type="text" name="name" size="6"></p>
<p>email</br>
<input typr="text" name="email" size="17" maxsize="40"></p>
<p>Your Feedback</br>
<input type="text" style="height:40px ;width:125px" name="feedback"></p>
<p><input type="submit" value="submit"></p>

</form>


(2)processfeedback.php

<?php
date_default_timezone_set("PRC");
$name=trim($_POST['name']);
$email=trim($_POST['email']);
$feedback=trim($_POST['feedback']);
$toaddress="xxxxxxxxx@qq.com";//此处是你要送达人的邮件地址
$emailcontent="customer name:".$name."feedback:".$feedback;
$subject="$feedback from wed site";
$fromaddress="From:xxxxx@localhost.com";//发件人即自己的邮件地址,随便写一个即可
mail($toaddress,$subject,$emailcontent,$fromaddress);//第一个参数是收件人地址,第二个是标题,第三个是内容,第四个是发件人地址
?>
<html xmlns="http://www.w3.org/1999/html">
<head>
<title>Bob's Auto Parts-Feedback Submitted</title>
</head>
<body>
<h1>Feed Back Submitted</h1>
<p>Your Feed back have been sent.</p>
<?php
echo nl2br($emailcontent);
?>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: