简体   繁体   English

为什么我的联系表格不起作用? loading.gif卡住了,什么也没发生

[英]Why won't my contact form work? the loading.gif is stuck and nothing happens

I have tried using my contact form with XAMPP i have configured .ini files etc. correctly to GMAIL for testing purposes. 我已尝试将联系表单与XAMPP一起使用,我已将.ini文件等正确配置为GMAIL以进行测试。 Can you see where I have made a mistake? 可以看到我在哪里弄错了吗?

I have even tried WAMP and still nothing works. 我什至尝试过WAMP,但仍然没有任何效果。

I changed the xwamp files as this guy suggested: How to configure XAMPP to send mail from localhost? 我按照这个人的建议更改了xwamp文件: 如何配置XAMPP从本地主机发送邮件?

HTML 的HTML

<form method="post" action="contact-form.php" name="contactform" id="contactform">
    <fieldset>
        <input name="name" type="text" id="name" placeholder="Name"/> 
        <input name="email" type="text" id="email" placeholder="Email"/>  
        <input name="subject" type="text" id="subject" placeholder="Subject"/> 
    </fieldset>
    <fieldset> 
        <textarea name="comments" cols="40" rows="3" id="comments" placeholder="Message"></textarea>
    </fieldset>
    <input type="submit" class="submit" id="submit" value="Send Message" />
</form>

JS JS

 $('#contactform').submit(function(){
    var action = $(this).attr('action');
    $("#message").slideUp(250,function() {
        $('#message').hide();
        $('#submit')
            .after('<img src="img/assets/cbp-loading.gif" class="loader" />')
            .attr('disabled','disabled');
        $.post(action, {
            name: $('#name').val(),
            email: $('#email').val(),
            subject: $('#subject').val(),
            comments: $('#comments').val(),
        },
            function(data){
                document.getElementById('message').innerHTML = data;
                $('#message').slideDown(250);
                $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
                $('#submit').removeAttr('disabled');
                if(data.match('success') != null) $('#contactform').slideUp(850, 'easeInOutExpo');
            }
        );
    });
    return false;   

PHP 的PHP

 <?php
if (isset($_POST["submit"])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = 'Message from Contact Demo ';
    $message = $_POST['message'];
    $from = 'Demo Contact Form'; 
    $to = 'myemail@gmail.com'; 
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
    mail('myemail@gmail.com', $name, $email, $subject, $message);
}
?>

Sendmail code (i have removed the email and password obviously) Sendmail代码(我显然已删除了电子邮件和密码)

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=MYEMAIL@gmail.com
auth_password=MY EMAIL PASSWORD
force_sender=MYEMAIL@gmail.com

One of the most underestimated points is to no start XAMPP as administrator. 最被低估的一点是,不要以管理员身份启动XAMPP。 In addition I'm missing some configuartions for smtp and co: 另外,我缺少smtp和co的一些配置:

 $smtp = Mail::factory('smtp', array( 'host' => 'ssl://smtp.gmail.com', 'port' => '465', 'auth' => true, 'username' => 'EMAIL', 'password' => 'PASSWORD' )); 

Those are necessary to be allowed to sent to your email adress. 那些必须被允许发送到您的电子邮件地址。 If not anyone could spam your email adress. 如果没有,任何人都可以通过垃圾邮件发送您的电子邮件地址。

Sincerely liqSTAR 真诚的liqSTAR

There's no mail() function in the PHP code. PHP代码中没有mail()函数。

Would recommend stripping back to the simplest test case to start with. 建议先剥离最简单的测试用例。 As a first test I would recommend writing a simple PHP file that just utilises the mail() function to send an email to your own address and returns the result (be sure to also check the PHP error log) - this will help to confirm PHP is configured with a working SMTP server. 作为第一个测试,我建议编写一个简单的PHP文件,该文件仅使用mail()函数将电子邮件发送到您自己的地址并返回结果(请确保还检查PHP错误日志)-这将有助于确认PHP配置了可以正常工作的SMTP服务器。

I'd then try the form submission without the use of JavaScript to ensure that it's submitting okay. 然后,我尝试不使用JavaScript来提交表单,以确保表单可以提交。 Does the $.post action appear in the console okay? $.post操作是否可以在控制台中显示? Does it show anything as the response or status code? 它是否显示任何内容作为响应或状态代码?

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

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