简体   繁体   English

提交联系表格而不使用PHP

[英]Submit Contact Form without using PHP

I'm still a student and today our lecturer told us that the only way in order to submit a contact us form without having to use the mailto: function is to use PHP. 我还是学生,今天我们的讲师告诉我们,无需使用mailto:function即可提交联系我们表单的唯一方法是使用PHP。

I swear that last year another lecturer showed us a way using only javascript. 我发誓,去年另一位讲师向我们展示了一种只使用javascript的方法。

Is it possible to submit a feedback/contact form using a basic form and javascript ? 是否可以使用基本表单和javascript提交反馈/联系表单? If so, do you mind sharing a sample example ? 如果是这样,你介意分享一个示例吗?

Thanks in advance 提前致谢

You can use JavaScript to redirect to mailto: with some parameters, but that isn't ideal. 您可以使用JavaScript重定向到mailto:使用一些参数,但这并不理想。 Also keep in mind that anything beyond an e-mail address in a mailto: URL is non-standard. 另请注意, mailto: URL中的电子邮件地址以外的任何内容都是非标准的。 While it will work for many browsers, it won't work for everything. 虽然它适用于许多浏览器,但它不适用于所有内容。

The best way to send e-mail is to do it server-side, using PHP or something else. 发送电子邮件的最佳方式是使用PHP或其他方式在服务器端执行此操作。

A form is created/submitted by the browser based on HTML. 浏览器基于HTML创建/提交表单。 JavaScript is commonly used to enhance forms (in many different ways). JavaScript通常用于增强表单(以许多不同的方式)。 Basic forms send their data as a POST request. 基本表单将其数据作为POST请求发送。 To do anything useful with the data you need server-side code to handle the POST request (such as PHP). 要对数据执行任何有用的操作,您需要服务器端代码来处理POST请求(例如PHP)。

You can't submit a form to javascript and expect it to do anything. 您无法向javascript提交表单并期望它可以执行任何操作。 You need a server side script in order to receive a form for processing. 您需要服务器端脚本才能接收表单以进行处理。 Mailto is a browser/os specific method and is not necessarily going to invoke anything. Mailto是一种特定于浏览器/操作系统的方法,不一定会调用任何东西。 Javscript can process your form before going to the server for further processing, but like I said you need to submit to a server. Javscript可以在进入服务器进行进一步处理之前处理你的表单,但就像我说你需要提交给服务器一样。

Javascript cant capture anything without PHP or browser support. 没有PHP或浏览器支持,Javascript无法捕获任何内容。 You need a server side script to receive a form and process it. 您需要服务器端脚本来接收表单并对其进行处理。 Javascript without PHP or another server side script can't capture form. 没有PHP或其他服务器端脚本的Javascript无法捕获表单。

You can use a service like emailjs.com : 您可以使用像emailjs.com这样的服务:

1) Configure EmailJS: 1)配置EmailJS:

<script type="text/javascript" src="https://cdn.emailjs.com/sdk/2.2.4/email.min.js"></script>
<script type="text/javascript">
   (function(){
      emailjs.init("user_USERID");
   })();
</script>

2) Send the Email: 2)发送电子邮件:

var service_id = 'my_mandrill';
var template_id = 'feedback';
var template_params = {
    name: 'John',
    reply_email: 'john@doe.com',
    message: 'This is awesome!'
};

emailjs.send(service_id,template_id,template_params);

It has a limit of 200 free emails per month, which will suite a resume/portfolio website. 它每月限制200封免费电子邮件,包含简历/投资组合网站。 reCaptcha is supported. 支持reCaptcha。

EmailJS supports different Email providers (including a custom SMTP server), and provides you with logs and statistics. EmailJS支持不同的电子邮件提供商(包括自定义SMTP服务器),并为您提供日志和统计信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM