今天,我尝试使用html、css和js创建一个表单,它将在运行代码时将响应发送到codes...but中输入的邮件ID --在单击Submit按钮后,响应不会在邮件上运行。下面是我尝试过的代码:
<!doctype html>
<html>
<head>
<meta name="viewport" content="width-device-width, initial-scale=1.0">
<title>codeG</title>
<link rel="stylesheet" href="Style.css">
</head>
<body>
<div class="container">
<form onsubmit="sendEmail(); reset(); return false;">
<h3> LOGIN FORM <hr width="50px" style="background: #555; height:5px"></h3>
<input type="text" id="name" placeholder="Full Name" required>
<input type="email" id="email" placeholder="Valid Email" required>
<input type="text" id="phone" placeholder="Valid Phone no." required>
<textarea id="message" rows="4" placeholder="Leave a comment..."></textarea>
<button type="Submit"> Submit </button>
</form>
</div>
<script src="https://smtpjs.com/v3/smtp.js">
</script>
<script>
function sendEmail(){
Email.send({
Host : "smtp.gmail.com",
Username : "ayushbharti.official123@gmail.com",
Password : "*********",
To : 'ayushbharti.official123@gmail.com',
From : document.getElementById("email").value,
Subject : "New Contact Form Equiry",
Body : "Name: " + document.getElementById("name").value
+ "<br> Email:" + document.getElementById("eamil").value
+ "<br> Phone no.:" + document.getElementById("phone").value
+ "<br> Message:" + document.getElementById("message").value
}).then(
message => alert("Message Sent Successfully")
);
}
</script>
</body>
</html>请试着解决我提到的路径
上的问题
发布于 2022-08-09 08:27:28
我认为您的form标签中有一个问题。
让我描述一下
function sendEmail() {
Email.send({
Host: "smtp.gmail.com",
Username: "ayushbharti.official123@gmail.com",
Password: "*********",
To: 'ayushbharti.official123@gmail.com',
From: document.getElementById("email").value,
Subject: "New Contact Form Equiry",
Body: "Name: " + document.getElementById("name").value +
"<br> Email:" + document.getElementById("eamil").value +
"<br> Phone no.:" + document.getElementById("phone").value +
"<br> Message:" + document.getElementById("message").value
}).then(
message => alert("Message Sent Successfully")
);
}<div class="container">
<!--first disable default action of the form -->
<form onsubmit="return false;sendEmail(); reset();">
<h3> LOGIN FORM
<hr width="50px" style="background: #555; height:5px">
</h3>
<input type="text" id="name" placeholder="Full Name" required>
<input type="email" id="email" placeholder="Valid Email" required>
<input type="text" id="phone" placeholder="Valid Phone no." required>
<textarea id="message" rows="4" placeholder="Leave a comment..."></textarea>
<button type="Submit"> Submit </button>
</form>
</div>
<script src="https://smtpjs.com/v3/smtp.js">
</script>
https://stackoverflow.com/questions/73287483
复制相似问题