想用PHP写个表单发邮件到邮箱里。
表单里面有姓名,性别等。。按提交后就直接能发到邮箱了。哪位好心人能提供下具体代码呢?网上找了很多都不行的
~~
编译通过后,我会追加分数滴~~
表单里面有姓名,性别等。。按提交后就直接能发到邮箱了。哪位好心人能提供下具体代码呢?网上找了很多都不行的
~~
编译通过后,我会追加分数滴~~
解决方案 »
- 怎么做一个背景颜色的复选框
- 关于建站,cms还有框架
- zend studio 不会用 怎么办
- php xajx的loading显示问题~~~~
- 上传文件时出现错误
- 多表查询之后如何应用结果?
- 急急,phpmyadmin出现下面错误The configuration file now needs a secret passphrase (blowfish_secret).
- 我的PHP编译系统已经配置好,我写好一个PHP的源程序。应该怎么编译
- 安装了apache和php4之后不能用的问题。
- 关于PHP公网项目获取访问者IP,却只能获取到局域网IP的情况
- PHP怎样执行BAT文件,或者其他可执行文件??
- 求助
项目主要是一个 公司要发送贺卡到用户邮箱 表单上面有对方邮箱地址 祝福话语等等 提交就直接发送到对方的邮箱里面了 用的是phpmailer类 如果 SMTP 用的是GMAIL 提供的
代码如下<?php
header("Content-type:text/html;charset=utf8");
require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录
include("class.smtp.php");
@$action = $_REQUEST['action'];
@$reciver_address = $_REQUEST['reciver_address'];
@$reciver_name = $_REQUEST['reciver_name'];
@$reciver_content = $_REQUEST['reciver_content'];
if($action == 'send'){
$mail = new PHPMailer(); //建立邮件发送类
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->CharSet = "UTF-8";
//$address = $_POST['address'];
$mail->IsSMTP(); // 使用SMTP方式发送
$mail->Subject = $reciver_name."祝贺您新春愉快"; //邮件标题
$mail->Username = "[email protected]"; // 邮局用户名(请填写完整的email地址)
$mail->Password = "xxxxx"; // 邮局密码
$mail->FromEmail = "[email protected]"; //邮件发送者email地址
//$mail->From = "[email protected]";
$mail->FromName = "xxxx";
$mail->AddAddress("$reciver_address", "");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
$mail->AddReplyTo("[email protected]", "xxxx");
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件
$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式
$html_content = file_get_contents('demo.html');
//$html_content = iconv("gb2312", "utf-8",html_content);
$html_content = str_replace('sender_name', $reciver_name, $html_content);
$html_content = str_replace('sender_content', $reciver_content, $html_content);
//$html_content = iconv("gb2312", "utf-8",html_content);
//create demo.html BEGIN staticdemo
$filename = 'email'.rand(1,10).date("YmdHis",time());
$filename = 'static/'.$filename.'.html';
$static_html = file_get_contents('static.html');
$static_html = str_replace('sender_name', $reciver_name, $static_html);
$static_html = str_replace('sender_content', $reciver_content, $static_html);
if(!file_exists($filename)){
$fp=fopen("$filename","w+");//fopen()的其它开关请参看相关函数
$str="$static_html";
fputs($fp,$str);
fclose($fp);
}
$html_content = str_replace('staticdemohtml', $filename, $html_content);
//create demo.html END
//$html_content = $html_content.'请勿回复!!';
//$html_content = eregi_replace("[\]",'',$html_content);
//$$html_content = "=?UTF-8?B?".base64_encode($html_content)."?=";
$mail->Body = $html_content;
//$mail->Body = iconv("GB2312","UTF-8", "$html_content"); //邮件内容
//$mail->Body = "$html_content"; //邮件内容
//$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略
if(!$mail->Send())
{
echo "Sorry! Sending Failure!!!";
echo "<a href='http://xxxxxx/bocigroup/fish.html'>BACK</a>";
}else{
echo "Congratulations! Sending Success!!!";
header("Location:http://xxxxx/bocigroup/back2.html");
}
}
?>
我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<?php
//header('Content-Type: text/html; charset=utf-8'); require_once(PEAR_PATH."class.phpmailer.php");
error_reporting(E_ERROR);
function smtp_mail ( $sendto_email, $subject, $body ,$att=array()) { //require = ("class.phpmailer.php"); //下载的文件必须放在该文件所在目录 $mail = new phpmailer(true); //建立邮件发送类 $address->$_POST['address'];
$mail->IsSMTP(); // 使用SMTP方式发送
$mail->Host = "mail.qq.com"; // 您的企业邮局域名
$mail->SMTPAuth = true; // 启用SMTP验证功能
$mail->Username = "[email protected]"; // 邮局用户名(请填写完整的email地址)
// $mail->Password = "******"; // 邮局密码
//$mail->From = "[email protected]"; //邮件发送者email地址
$mail->FromName = "开心果";
$mail->[email protected]("$address", "");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名") //$mail->AddReplyTo("", "");
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件
//$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式
$mail->Subject = "PHPMailer测试邮件"; //邮件标题
$mail->Body = "Hello,这是测试邮件"; //邮件内容
$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略
if(!$mail->Send())
{
echo "邮件发送失败. <p>";
echo "错误原因: " . $mail->ErrorInfo;
exit;
}
echo "邮件发送成功"; ?>
}
</body>
</html>