我正在为我们学校的网站制作一份表格,并希望它自动将信息发送到电子邮件地址。我正在使用html编码,我知道它可以完成,但我正在使用的编码打开我的电子邮件发送它。我希望他们点击提交,它会自动转到电子邮件。有人可以给我正确的代码吗?我在这里找到的代码打开了我的电子邮件,以便发送此信息。我需要跳过此步骤并在我单击提交时自动发送。谢谢你的帮助。
答案 0 :(得分:1)
你需要一种服务器端语言,比如php,而不仅仅是html。
以html格式
<form class="submit-student-form" action="submit_student_form.php" method="post">
<h1 class="form-title">Student Detail Form</h1>
<label>Name</label>
<input type="text" name="first_name" placeholder="Robert Thomas" required>
<label>Email</label>
<input type="email" name="email" placeholder="Email ID" required>
<label>Contact Number</label>
<input type='tel' name="telephone" placeholder="+91 91234567890" required>
<label>Home Location</label>
<input type="text" name="location" placeholder="New York" required>
<label>Address</label>
<input type="text" name="address" placeholder="Loreum Ipsum" required>
<button type="submit">Submit</button>
</form>
创建一个php文件submit_student_form.php
<?php
if(isset($_POST['email'])) {
$email_to = "to@domain.com";
$email_subject = "Email subject";
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$location = $_POST['location']; // required
$address = $_POST['address']; // required
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message = "Form details below.\n\n";
$email_message .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Location: ".clean_string($location)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<div class="feedback">Thank you for contacting us. We will be in touch with you very soon.</div>
<?php
}
?>
答案 1 :(得分:0)
提示 - 另外尝试添加一些代码以及问题,它可以帮助我们所有人更准确地回答。
答案 2 :(得分:0)
所以我假设,如果你说你用电子邮箱打开它,你就使用了“mailto”命令。我总是使用它将信息邮寄到特定的电子邮件。如果我理解,你试图发送电子邮件而不打开那个讨厌的电子邮箱,对吧?好吧,我不建议那样,计算机将如何知道从哪里发送电子邮件?如果你想查看“mailto”的事情,那么here是一个很棒的网站,上面有关于如何使用它的例子。祝你学校的网站好运!
答案 3 :(得分:0)
您可以使用Google的Gmail Javascript API实现此功能。
请参阅:https://www.sitepoint.com/sending-emails-gmail-javascript-api/
<强> 1。启用Gmail API : 导航到Google Developer Console并创建一个项目并生成API密钥。
<强> 2。初始设置::
git clone git@github.com:sitepoint-editors/gmail-api-javascript-example.git
第3。输入我们的凭证: 您应该在index.html中输入您的凭据:
var clientId = 'xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com';
var apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
修改index.html中的范围变量定义
var scopes =
'https://www.googleapis.com/auth/gmail.readonly '+
'https://www.googleapis.com/auth/gmail.send';
<强> 4。添加“撰写”按钮。
<a href="#compose-modal"
data-toggle="modal"
id="compose-button"
class="btn btn-primary pull-right">Compose</a>
“撰写”按钮只会打开一个模型,我们也将直接添加到DOM中。
<强>撰写-modal.html 强>
<div class="modal fade" id="compose-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Compose</h4>
</div>
<form onsubmit="return sendEmail();">
<div class="modal-body">
<div class="form-group">
<input type="email" class="form-control" id="compose-to" placeholder="To" required />
</div>
<div class="form-group">
<input type="text" class="form-control" id="compose-subject" placeholder="Subject" required />
</div>
<div class="form-group">
<textarea class="form-control" id="compose-message" placeholder="Message" rows="10" required></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" id="send-button" class="btn btn-primary">Send</button>
</div>
</form>
</div>
</div>
</div>
发送电子邮件功能:
function sendEmail()
{
$('#send-button').addClass('disabled');
sendMessage(
{
'To': $('#compose-to').val(),
'Subject': $('#compose-subject').val()
},
$('#compose-message').val(),
composeTidy
);
return false;
}
答案 4 :(得分:0)
这对我有用。
创建一个名为done.php的文件,并通过POST将您的sineup表单链接至done.php
将此添加到done.php
<?php
if(isset($_POST['email'])) {
$email_to = "email";
$email_subject = "subject";
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$password = $_POST['password'];
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message = "Form details below.\n\n";
$email_message .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "password: ".clean_string($password)."\n";
// email
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<div class="feedback">Thanks for submiting we will get back to you as soon as possable</div>
<?php
}
?>