1. 导出csv文件的代码 参考http://www.zxbc.cn/html/cxrs/150837493859_2.html
<?php require_once('inc/conn.php'); ?>
<?php
$sql="select * from cge_userinfo";
$result=mysql_query($sql);
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=mail.csv");
echo "username,";
echo "Email/t/n";
while($rs=mysql_fetch_object($result)){
echo $rs->username.",";
echo $rs->email."/t/n";
}
?>
2. 注册的用户邮箱发邮件的代码
<?php require_once('inc/conn.php'); ?>
<?php
//写入数据库
$username=$_POST[username];
$email=$_POST[email];
$sql_insert="insert into cge_userinfo values('','".$username."','".$email."')";
mysql_query($sql_insert);
$subject = "Welcome to CGE"; //给用户发送email主题
$from = "info@chinaglobalexchange.com";
$headers= 'Content-type: text/html; charset=utf-8'."/r/n"."From:".$from;
$attachment= "mail.html";
$fp = fopen($attachment, "r"); //打开HTML文件
$body= fread($fp, filesize($attachment)); //把整个文件读入一个变量
$body= str_replace("***",$username,$body); //收件人名称替换,一般用于群发
mail($email, $subject, $body, $headers);
?>
<script language="javascript">
alert("Thank you! You have sent your name and email successful.");
window.location.href="http://www.chinaglobalexchange.net/study.html";
</script>