PHP Email Form Trouble

时间:2014-02-12 20:07:29

标签: javascript php jquery ajax

我前一段时间创建了这个表单并且工作正常,但由于某种原因它现在根本不能正常工作。我不知道为什么有人可以为我阐明这一点。

此表单的功能是将信息同时发布到两个地方。一个通过表格动作&另一个通过javascript函数。

以下是表格:

<form action="http://oi.vresp.com?fid=0cf1b59e3b" method="POST">                

<input type=hidden name="retURL" value="http://www.farms.com/contact-us-thanks">

<div class="row">
<div><label for="first_name">First Name<font color=#bd0000>*</font></label><input class="required" id="first_name" maxlength="40" name="first_name" size="20" type="text" />   </div>
<div><label for="last_name">Last Name<font color=#bd0000>*</font></label><input  class="required" id="last_name" maxlength="80" name="last_name" size="20" type="text" /></div>
</div>
                   <div class="row">
                        <label for="email">Email<font color=#bd0000>*</font></label><input class="required"  id="email" maxlength="80" name="email" size="20" type="text" />
                        <!--<label for="zip"><strong>Zip</strong></label><input  id="zip" maxlength="20" name="zip" size="20" type="text" /> -->
                   </div>
                   <div class="row">
                        <label for="email">Interested in<font color=#bd0000>*</font></label><br />
                        <label class="cf" style="clear: both;"><input  id="00N30000006mral" name="00N30000006mral" type="checkbox" value="1" />Real Estate</label>
                        <label class="cf"><input  id="00N30000006mraq" name="00N30000006mraq" type="checkbox" value="1" /> Membership</label>
                        <label class="cf"><input  id="00N30000006mraq1" name="00N30000006mraq1" type="checkbox" value="1"  /> Outings</label>
                   </div>
                   <input type="hidden" id="recordType" name="recordType" value="01230000000nCt1">
                    <div class="row">
                        How did you hear about us?<br />
                        <textarea  id="00N3000000B6ZCD" name="00N3000000B6ZCD" type="text" wrap="soft"></textarea>
                    </div> 
                    <div class="row">                    
                        <label for="description">Comments/Questions</label><br /><textarea id="description" name="description" type="text" wrap="soft"></textarea>
                    </div>
                    <div class="row">                    
                        Type in "<strong>Creighton Farms</strong>" (case sensitive)                            
                    </div>                        
                    <div class="row">
                        <label id="Security">Security Code<font color=#bd0000>*</font></label><input class="required" id="security_code" maxlength="40" name="security_code" size="10" type="text" />                                                         
                    </div>  
                    <div class="row button-submit"><input type="image" name="submit" id="btnSubmit" name="btnSubmit" src="<?php bloginfo( 'template_url' ); ?>/images/submit-ct.png"></div>
                </form>

这是Javascript函数

$.ajax({
 type: 'POST',
                url: '/wp-content/themes/farms/captcha/form.php',
                data: { 'first_name': $('#first_name').val(),
                        'last_name': $('#last_name').val(),
                        'email': $('#email').val(),
                        'zip': $('#zip').val(),
                        'cf_real': $('#00N30000006mral').attr('checked'),
                        'cf_member': $('#00N30000006mraq').attr('checked'), 
                        'cf_outing': $('#00N30000006mraq1').attr('checked'),                       
                        'how_about': $('#00N3000000B6ZCD').val(),
                        'description': $('#description').val(),
                        'security_code': $('#security_code').val()
                      },  
                async: false,
                success: function(data){
                    ok  = false;
                    if(data=="OK") {
                        ok_submit  = true;                          
                        alert('Your form has been successfully sent. Thank you for your staying tuned with us.');                               
                    } else {
                        alert(data);
                        ok_submit  = false;
                    }
                },
                error: function(){}
            });

        }
        return ok_submit;
    });

这是PHP函数:     

$message = 'Hi Admin<br /><br />
            Below is the message sent from "Contact Us" page in www.creightonfarms.com:<br /><br />
            First Name: '.$_POST['first_name'].'<br />
            Last Name: '.$_POST['last_name'].'<br />                
            Email: '.$_POST['email'].'<br /> 
            Interested in: CF - Prospects (Real Estate): '.   ($_POST['cf_real']=='checked'?'Yes':'No').
                        '&nbsp;&nbsp;&nbsp;&nbsp;CF -  Membership: '.($_POST['cf_member']=='checked'?'Yes':'No').   
                        '&nbsp;&nbsp;&nbsp;&nbsp;CF -  Outings: '.($_POST['cf_outing']=='checked'?'Yes':'No').'<br />
            How did you hear about us? <br />- '.$_POST['how_about'].'<br />                                        
            Comments/Questions:<br />
            - '.$_POST['description'].'<br />
            --------------------------------------------------------------------------------------------------------------------<br />
           This message is automatically sent from http://www.farms.com';

    $to      = 'test@test.com';
    $subject = 'Farms - Contact Us';
    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= 'From: Farms <info@farms.com>' . "\r\n";        
    $headers .= 'Cc: more@farms.com'.'\r\n';

    $send = mail($to, $subject, $message, $headers);
    if($send){
        print 'OK';
     } else
        print 'NO';

} else {
// Insert your code for showing an error message here
echo 'Sorry, you have provided an invalid security code';   
}
unset($_SESSION['security_code']);
?>

0 个答案:

没有答案