require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录
$mail = new PHPMailer(); //建立邮件发送类
$mail->IsSMTP(); // 使用SMTP方式发送
$mail->Host = "smtp.163.com"; // 您的企业邮局域名
$mail->SMTPAuth = true; // 启用SMTP验证功能
$mail->Username = "jsshedu@163.com"; // 邮局用户名(请填写完整的email地址)
$mail->Password = "123456"; // 邮局密码
$mail->From = "jsshedu@163.com"; //邮件发送者email地址
$mail->FromName = $name;
$mail->AddAddress("$address", "$name");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
//$mail->AddReplyTo("", "");
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件
$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式
$mail->Subject = $title; //邮件标题
$mail->Body ="
姓名:$name <br>
电话:$tel <br>
邮箱:$mymail <br>
内容:$Content
"; //邮件内容
$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略
if(!$mail->Send())
{
echo "邮件发送失败,三秒后返回主页... <p>";
echo "错误原因: " . $mail->ErrorInfo;
exit;
}
header("refresh:3; url=index.html");
echo "邮件发送成功,三秒后返回主页...";
?>
test.php
<p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">