jquery提交联系表格

时间:2015-01-31 17:33:22

标签: php jquery forms email

我正在尝试隐藏表单并在邮寄邮件后显示成功提示。

但我所做的一切,都被代码忽略了,我在邮件功能之前放了标题,邮件仍然发送,它应该在邮件发送之前重定向,试图在邮件功能之前破解代码,以及中断函数作品。 在列表中邮件不发送。

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:

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';
}

编辑:

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

尝试在邮件之前重定向只是为了检查,但它只是忽略了标题并仍然邮寄邮件。

edit2:

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

不能正常工作。

1 个答案:

答案 0 :(得分:0)

将id = sbc添加到

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