<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无后台网站发送邮件方法(formspree)开通黄金会员才能使用AJAX提交,否则只能使用form提交</title>
</head>
<body>
<form id="content">
<input type="text" name="name" placeholder="输入你的姓名"/>
<input type="email" name="_replyto" placeholder="输入你的邮箱"/>
<input type="button" value="发送" id="btn"/>
//更多name属性参考https://formspree.io
</form>
</body>
<script src="../js/jquery-3.3.1.min.js"></script>
<script>
$("#btn").on("click",function(){
var obj = $("#content").serialize(); //获取id为content的form表单里面的内容,name值均为formspree提供不能更改
$.ajax({
type:"post", //必须post请求
url:"https://formspree.io/abc@qq.com", //abc@qq.com换成你要接收的邮箱地址
async:true,
data:obj,
dataType:"json",
success: res=>{
alert('邮件已发送!!!'); //发送成功后的操作
},
error:res=>{
alert("未知错误,发送失败");
}
});
})
</script>
</html>