简体   繁体   English

无法获取PHP模态联系表来提交电子邮件

[英]Can't get PHP modal contact form to submit email

The modal form below gets stuck on submitting.... It also doesn't actually send the message to my email. 下面的模式表单在提交时会卡住...。它实际上也不会将邮件发送到我的电子邮件中。 I am relatively new to PHP, but I assume this problem pertains to my sendmessage.php file(below). 我对PHP相对较新,但是我认为这个问题与我的sendmessage.php文件有关(如下)。 For whatever reason, the tutorial states to not apply an action. 无论出于何种原因,本教程都声明不执行操作。 What coud I be doing wrong? 我做错了什么?

Just FYI, my header contains scripts to jquery.fancybox.js?v=2.0.6 and ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js 仅供参考,我的标头包含了jquery.fancybox.js?v=2.0.6ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

sendmessage.php file: sendmessage.php文件:

<?php
$sendto   = "jjaylad@me.com";
$usermail = $_POST['email'];
$content  = nl2br($_POST['msg']);

$subject  = "New Feedback Message";
$headers  = "From: " . strip_tags($usermail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";

$msg  = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>New User Feedback</h2>\r\n";
$msg .= "<p><strong>Sent by:</strong> ".$usermail."</p>\r\n";
$msg .= "<p><strong>Message:</strong> ".$content."</p>\r\n";
$msg .= "</body></html>";


if(@mail($sendto, $subject, $msg, $headers)) {
    echo "true";
} else {
    echo "false";
}

?>

Contact form code: 联系表格代码:

    <form id="contact" name="contact" action="#" method="post">
    <label for="email">Your E-mail Address:</label>
    <input type="email" id="email" name="email" class="txt">
    <br>
    <label for="msg">Inquiry:</label>
    <textarea id="msg" name="msg" class="txtarea"></textarea>

    <button id="send">Send E-mail</button>
</form>

The form action should point to sendmessage.php 表单action应指向sendmessage.php

<form id="contact" name="contact" action="sendmessage.php" method="post">
    <label for="email">Your E-mail Address:</label>
    <input type="email" id="email" name="email" class="txt">
    <br>
    <label for="msg">Inquiry:</label>
    <textarea id="msg" name="msg" class="txtarea"></textarea>
    <button id="send">Send E-mail</button>
</form>

I think you may be missing a file. 我认为您可能缺少文件。

I get a 404 error when submitting. 提交时出现404错误。 http://www.jjayladslair.com/sendmessage.php does not exist. http://www.jjayladslair.com/sendmessage.php不存在。

Double check the filenames? 仔细检查文件名?

*edit: *编辑:

Just noticed that you are in fact using $.ajax to process the form. 只是注意到您实际上是在使用$ .ajax处理表单。 It's most definitely a case of a missing file, or incorrect filename. 绝对是文件丢失或文件名不正确的情况。 The 404 error causes a jQuery exception which then stops the execution of the Javascript function. 404错误导致jQuery异常,该异常随后停止执行Javascript函数。 That's why the form gets stuck on submit. 这就是表单停留在提交状态的原因。

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

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