【问题标题】:Contact Form with Javascript带有 Javascript 的联系表
【发布时间】:2016-03-24 08:27:32
【问题描述】:

您好, 我正在尝试使用 Javascript 创建一个用于自学的 Windows 10 应用程序。今天我想尝试,发送一封带有消息的电子邮件,联系表格中的姓名。我只是 Javascript 的初学者。有人可以用例子写一个短代码吗?我有一个使用 PHP 的联系表,但是如何使用 Javascript 发送邮件?

<form method="post" action="send.js">
    <input type="text" placeholder="Name" name="name" id="name" required=" ">
    <input type="email" placeholder="Email" name="email" id="email" required=" ">
    <textarea placeholder="Message..." name="msg" id="msg" required=" "></textarea>
    <input type="submit" value="Submit">
</form>

谢谢

【问题讨论】:

    标签: javascript email win-universal-app winjs contact-form


    【解决方案1】:

    如果您想通过 JavaScript 发送电子邮件,请使用 Node.js Nodemailer。 https://nodemailer.com/Nodemailer - Send e-mails with Node.JS

    【讨论】:

      【解决方案2】:

      你也可以使用

       <a href="mailto:someone@example.com">Send email</a>
      

      这将打开用户设备上的默认邮件应用程序,并使用该电子邮件地址自动填写 To: 字段。

      Here is an example of how it works.

      还可以在 URL 中指定标头(例如主题、抄送等)和消息正文的初始值。不能嵌入空格、回车和换行,但必须进行百分比编码。

      <a href="mailto:someone@example.com?subject=This%20is%20the%20subject&cc=someone_else@example.com&body=This%20is%20the%20body">Send email</a>
      

      【讨论】:

        【解决方案3】:

        据我所知,您无法使用 javascript 发送邮件。通常您会使用 javascript 将表单发送到您的 php 页面。您可以使用 jquery 和 ajax 之类的东西将表单添加到您的 php 脚本中,这样:

        $(document).ready(function(){
            $('#your-form-id').on('submit', function(){
                var formData = $(this).serialize
                $.ajax({
                    type: 'post',
                    url: 'your_url.php',
                    data: formData,
                    dataType: 'json',
                    success: function(response){
                        //Anything you want to do after form is submitted
                    }
                });
            });
        });
        

        这不是经过测试的代码,但我认为它应该大致正确。

        【讨论】:

          猜你喜欢
          • 2018-03-06
          • 2019-04-19
          • 2020-05-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-03-05
          • 2020-07-23
          • 2020-02-16
          相关资源
          最近更新 更多