0

最近,我一直在尝试使联系表起作用,经过数小时的努力,我终于做到了。 http://trulyamped.com/democon/contact2.php 此联系表格完美运行,电子邮件被发送到我的帐户。我唯一想知道的是如何使联系表单在 .html 文件中工作。我不希望它在 .php 文件中。我已经尝试将文件保存为 .html 文件,但它不起作用。请告诉我。所以几乎我希望它是contact2.html并且仍然能够工作。

4

3 回答 3

0

您将需要创建一个只有电子邮件处理逻辑的第二个页面,让我们调用它,email.php然后您可以更新您的表单以发布email.php并将此页面更改contact2.html为只要它发布到.php它将工作的文件。

<form id="contact-us" action="email.php" method="post">
于 2013-07-22T01:07:13.073 回答
0

您的赌注是为主表单使用 AJAX,但仍需要服务器端脚本页面来处理邮件发送。据我所知,不可能从客户端发送邮件。

所以

  1. 将实际发送邮件的 PHP 页面放在单独的脚本文件中
  2. 在 HTML 中创建您的表单并使用 AJAX 从您的 HTML 页面中调用邮件发送脚本。

这样您就可以将您的页面放在 html 中,并在后台进行邮件发送。

关于使用 .html 扩展名保存您的页面,这当然是行不通的。因为您的页面包含 PHP,它是服务器端的,需要一个 Web 服务器来运行,而 html 可以在任何设备上的任何简单浏览器上运行。

于 2013-07-22T01:08:06.233 回答
0

首先,为什么重要?

但是假设它确实很重要,您可能有几个选择。它们取决于您的代码所在的位置以及它当前的作用。如果页面有 PHP 代码需要在服务器端执行,那么它需要由 PHP 解释器在服务器端进行处理。要使用 HTML 文件执行此操作,您需要配置服务器以将.html文件视为.php服务器端处理的文件。不过,这并不理想。HTML 本身不需要通过 PHP 解释器运行。所以最好将 PHP 和 HTML 文件分开。

Another option could simply be to separate the client-side HTML form and the server-side PHP code into two separate files. Something like contact.html and contactProcessor.php. In the HTML file you'd just post to the PHP file in the form. Something like this:

<form action="contactProcessor.php" method="post">

This would cause the form to post the data to the PHP file. Then the PHP file can process the data, do whatever you're currently doing server-side, and redirect the user to another HTML file as a response. So at no point would the user be "viewing" a PHP file. There's just be one used to handle the form post.

Again, I can't imagine why it matters though.

于 2013-07-22T01:09:51.370 回答