setmail();//查询最新可用的邮件(接受者)
// 查询最新可用模板内容
// 查询最新可用企业邮箱(发送者)
}functionsetmail(){$data['username'] = "24066@qq.com";$data['password'] = "ntpcbibe";$data['form'] = "24068@qq.com";$data['address'] = "67992@qq.com";$data['replyto'] = "24068@qq.com";$data['subject'] = "邮件标题";$data['body'] = "邮件内容";$data['altbody'] = "邮件非html内容";$jieguo = postmail($data);if($jieguo){echo "发送成功";
}else{echo "发送失败";
}
}function postmail($postmail){if(empty($postmail)){return false;
}else{$mail = new PHPMailer(true);try{//服务器配置
$mail->CharSet ="UTF-8"; //设定邮件编码
$mail->SMTPDebug = 0; //调试模式输出
$mail->isSMTP(); //使用SMTP
$mail->Host = 'smtp.qq.com'; //SMTP服务器
$mail->SMTPAuth = true; //允许 SMTP 认证
$mail->Username = $postmail['username']; //SMTP 用户名 即邮箱的用户名
$mail->Password = $postmail['password']; //SMTP 密码 部分邮箱是授权码(例如163邮箱)
$mail->SMTPSecure = 'ssl'; //允许 TLS 或者ssl协议
$mail->Port = 465; //服务器端口 25 或者465 具体要看邮箱服务器支持
$mail->setFrom($postmail['form'], ''); //发件人
$mail->addAddress($postmail['address'], ''); //收件人
//$mail->addAddress('ellen@example.com'); // 可添加多个收件人
$mail->addReplyTo($postmail['replyto'], ''); //回复的时候回复给哪个邮箱 建议和发件人一致
//$mail->addCC('cc@example.com'); //抄送
//$mail->addBCC('bcc@example.com'); //密送
//发送附件
// $mail->addAttachment('../xy.zip'); // 添加附件
// $mail->addAttachment('../thumb-1.jpg', 'new.jpg'); // 发送附件并且重命名
//Content
$mail->isHTML(true); //是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
$mail->Subject = $postmail['subject'];$mail->Body = $postmail['body']; //内容
$mail->AltBody = $postmail['altbody'];$mail->send();return true;
}catch (Exception $e) {//echo '邮件发送失败: ', $mail->ErrorInfo;
return false;
}
}
}