邮件没发送! Firebug显示jQuery错误 - JS Validation& AJAX

时间:2016-11-04 07:28:25

标签: jquery json ajax

我无法发送邮件。

表单链接为http://thewaitts.com/DemoSite/job.html Firebug显示了一些我没有得到的jQuery错误。 它刚刚工作并上传文件,但现在没有提交提交。请帮忙。

 if ($(this).valid()){

            var submitContact = $('#submit_form'),
            message = $('#msg');

            submitContact.on('click', function(){
        
            var formData = new FormData($('#solid-form')[0]); 
              
            var $this = $(this);
            var recaptchaResponse = grecaptcha.getResponse();
             if(recaptchaResponse.length!=0){
                $.ajax({
                    type: "POST",
                    url: 'job.php',
                    dataType: 'json',
                    cache:false,
                    processData: false,
                    contentType: false,
                    data: formData,
                    success: function(data) {

                    if(data.info !== 'error'){
                    $this.parents('form').fadeOut("slow");
                           // $this.parents('form').find('input[type=text],textarea,select').filter(':visible').val('');
                            message.hide().removeClass('success').removeClass('error').addClass('success').html(data.msg).fadeIn('slow');
                        } else {
                            message.hide().removeClass('success').removeClass('error').addClass('error').html(data.msg).fadeIn('slow');
                        }
                      }
                    });
                 }else{
                   message.hide().removeClass('success').removeClass('error').addClass('error').html("Please validate reCaptcha.").fadeIn('slow').delay(3000).fadeOut('slow');
                 }
                });
          }
          
           event.preventDefault();

        });
        });

<?php 

	/* ==========================  Define variables ========================== */

	#Your e-mail address
	define("__TO__", "asjadrex@gmail.com");
	

	#Message subject
	define("__SUBJECT__", "Website Visitor Message");

	#Success message
	define('__SUCCESS_MESSAGE__', "Thanks for your interest in Sapphire! <br> We will review your information and get back to you.");

	#Error message 
	define('__ERROR_MESSAGE__', "Error, your message hasn't been sent");

	#Messege when one or more fields are empty
	define('__MESSAGE_EMPTY_FILDS__', "Please fill out  all fields");

	/* ========================  End Define variables ======================== */

	//Send mail function
	function send_mail($to,$subject,$message,$headers){
		if(@mail($to,$subject,$message,$headers)){
			echo json_encode(array('info' => 'success', 'msg' => __SUCCESS_MESSAGE__));
		} else {
			echo json_encode(array('info' => 'error', 'msg' => __ERROR_MESSAGE__));
		}
	}

	//Check e-mail validation
	function check_email($email){
		if(!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
			return false;
		} else {
			return true;
		}
	}
	function check_phone($phone){
		if(strlen($phone)==10){
			return true;
		} else {
			return false;
		}
	}

	//Get post data
	if(isset($_POST['email']) and isset($_POST['phone'])){
		$fname 	 = $_POST['firstname'];
		$lname 	 = $_POST['lastname'];
		$email 	 = $_POST['email'];
		$phone 	 = $_POST['phone'];
		$address 	 = $_POST['address'];
		$city 	 = $_POST['city'];
		$state 	 = $_POST['state'];
		$zip 	 = $_POST['zip'];

		$uscitizen 	 = $_POST['uscitizen'];
		$work_loc		= $_POST['work_loc'];
		$positions 	 = $_POST['positions'];
		

		if(isset($_FILES['headshot'])){
	      $errors= array();
	      $file_name = $_FILES['headshot']['name'];
	      $file_size =$_FILES['headshot']['size'];
	      $file_tmp =$_FILES['headshot']['tmp_name'];
	      $file_type=$_FILES['headshot']['type'];
	      $file_ext=strtolower(end(explode('.',$_FILES['headshot']['name'])));
      
	      move_uploaded_file($file_tmp,"uploads/".$file_name);
	      /*$headshot_link = 'http://' . $_SERVER['HTTP_HOST'] . "/DemoSite/uploads/".$file_name;*/
	   }


	   	if(isset($_FILES['resume'])){
	      $errors= array();
	      $file_name = $_FILES['resume']['name'];
	      $file_size =$_FILES['resume']['size'];
	      $file_tmp =$_FILES['resume']['tmp_name'];
	      $file_type=$_FILES['resume']['type'];
	      $file_ext=strtolower(end(explode('.',$_FILES['resume']['name'])));
      
	         move_uploaded_file($file_tmp,"uploads/".$file_name);
	        /* $resume_link = 'http://' . $_SERVER['HTTP_HOST'] . "/DemoSite/uploads/".$file_name;*/
	   }

	  

		/*if($name == '') {
			echo json_encode(array('info' => 'error', 'msg' => "Please enter your name."));
			exit();
		} else if($mail == '' or check_email($mail) == false){
			echo json_encode(array('info' => 'error', 'msg' => "Please enter valid e-mail."));
			exit();
		} else if($phone == '' or check_phone($phone) == false){
			echo json_encode(array('info' => 'error', 'msg' => "Enter valid Phone Number (10 digit Max)"));
			exit();
		} else if($comment == ''){
			echo json_encode(array('info' => 'error', 'msg' => "Please enter your message."));
			exit();
		} else {*/
			//Send Mail
			$to = __TO__;
			$subject = __SUBJECT__;
			$message = '
			<html>
			<head>
			  <title>Mail from '. $fname .' '. $lname .'</title>
			</head>
			<body>
			  <table class="table">
				<tr>
				  <th align="right">First Name:</th>
				  <td align="left">'. $fname .'</td>
				</tr>
				<tr>
				  <th align="right">Last Name:</th>
				  <td align="left">'. $lname .'</td>
				</tr>
				<tr>
				  <th align="right">E-mail:</th>
				  <td align="left">'. $email .'</td>
				</tr>
				<tr>
				  <th align="right">Type Event:</th>
				  <td align="left">'. $phone .'</td>
				</tr>
				';
				
				$message .='<tr>
				  <th align="right">Street Address:</th>
				  <td align="left">'. $address .'</td>
				</tr>				
				<tr>
				  <th align="right">City:</th>
				  <td align="left">'. $city .'</td>
				</tr>
				<tr>
				  <th align="right"> State:</th>
				  <td align="left">'. $state .'</td>
				</tr>
				<tr>
				  <th align="right"> Zip Code:</th>
				  <td align="left">'. $zip .'</td>
				</tr>
				<tr>
				  <th align="right"> U.S. Citizen:</th>
				  <td align="left">'. $uscitizen .'</td>
				</tr>
				';


				$message .='<tr>
				  <th align="right">Work Location:</th>
				  <td align="left">'. $work_loc .'</td>
				</tr>				
				<tr>
				  <th align="right">Position:</th>
				  <td align="left">'. $positions .'</td>
				</tr>
				<tr>
				  <th align="right">Link to Headshot:</th>
				  <td align="left">'. $headshot_link .'</td>
				</tr>
				<tr>
				  <th align="right">Link to Resume:</th>
				  <td align="left">'. $resume_link .'</td>
				</tr>
			  </table>
			</body>
			</html>
			';

			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
			/*$headers .= 'From: ' . $mail . "\r\n";*/
			$headers .= 'From: onlinebooking@nysapphire.com'."\r\n";

			send_mail($to,$subject,$message,$headers);
			
		}
	else {
		echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FILDS__));
	}
 ?>

0 个答案:

没有答案