简体   繁体   English

jQuery提交联系表格

[英]jquery submit contact form

I'm trying to hide the form and show the success alert after the mail is mailed. 邮件寄出后,我试图隐藏表单并显示成功警报。

But everything I do, is ignored by the code, I put header before the mail function, and the mail still sends, it should redirect before the mail sends, tried to break the code before the mail function, and the break functions works. 但是我所做的一切,都被代码忽略了,我将标头放在mail函数之前,并且邮件仍然发送,它应该在邮件发送之前重定向,尝试在mail函数之前中断代码,并且break函数起作用。 at list the mail doesn't send. 在列表中,邮件未发送。

contact.php: contact.php:

<div id="innerWrapper">
    <h1 class="pageheading"><?=translate('contact_us') ?></h1>
    <form class="form-horizontal" action="/ajax/contact.php" method="POST" id="contactForm">
        <?php $email = $db->get_row("SELECT email,full_name FROM users WHERE userID = 1");?>
        <label><?=translate('your_name') ?>:</label> 
        <input type="text" name="name" <?php if($usersObject->ID()) {echo 'value = "'. $email->full_name. '"';} else {echo 'placeholder = "First / Last"';}?> class="required input-xlarge"/>
        <br/><br/>
        <label><?=translate('email') ?>:</label> 
        <input type="email" name="email" <?php if($usersObject->ID()) {echo 'value = "'. $email->email . '"';} else {echo 'placeholder = "email@example.com"';}?> class="required input-xlarge"/>
        <br/><br/>
        <label>Subject:</label> 
        <input type="text" name="<?=translate('subject') ?>" placeholder="Hi" class="required input-xlarge"/>
        <br/><br/>
        <label><?=translate('message') ?>:</label> 
        <textarea name="message_to_us" class="input-xlarge required" rows="5" placeholder=""></textarea>
        <br/><br/>
        <input class="btn btn-large btn-warning" value="<?=translate('contact_btn') ?>" type="submit" name="sbc"/>
    </form>
</div>

ajax/contact.php : ajax / contact.php:

if(isset($_POST['sbc'])) {

foreach($_POST as $K=>$V) $_POST[$K] = trim(strip_tags($V));
extract($_POST);

foreach($_POST as $k=>$v) {
    if(trim($v) == "") 
    {
        print '<div class="alert alert-error">All fields are required</div>';
        exit;
    }
}

$body = 'New contact form message on ' . $_SERVER['SERVER_NAME'];
$body .= '<br/>';
$body .= 'Subject : ' . $Subject;
$body .= '<br/>';
$body .= 'Name : '.$name .' / Email : ' . $email;
$body .= '<br/>';
$body .= $message_to_us;

$headers = "From: contact@" . str_replace("www.", "", $_SERVER['SERVER_NAME']) . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";

mail(PAYPAL_EMAIL, str_replace("www.", '', $_SERVER["SERVER_NAME"]), $body, $headers);


?>
<script type="text/javascript">
$("#sbc").click(function() {
    $("#contactForm").hide('slow');
});
</script>
<?php
    print '<div class="alert alert-success">'.translate('thankyou_contact').'</div>';
}else{
    print 'Emtpy request';
}

edit: 编辑:

$headers .= "Content-Type: text/html; charset=utf-8\r\n";
header('Location: join');
mail(PAYPAL_EMAIL, str_replace("www.", '', $_SERVER["SERVER_NAME"]), $body, $headers);

tried to redirect before the mail just to check, but it just ignores the header and still mail the mail. 尝试在邮件进行重定向之前只是为了进行检查,但它只是忽略了标头并仍然通过邮件发送邮件。

edit2 : edit2:

<script type="text/javascript">
    $(document).ready (function() {
        $("#sbc").click(function() {
            $("#contactForm").hide('slow');
        });
    });
    </script>

not working. 不工作。

将id = sbc添加到

 <input class="btn btn-large btn-warning" value="<?=translate('contact_btn') ?>" type="submit" name="sbc" id="sbc"/>

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

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