2015-12-27 93 views
2
$location ="/contact.php"; 
if(isset($_POST[$form_names['email']], $_POST[$form_names['subject']], $_POST[$form_names['mess']])){ 

     if($csrf->check_valid('post')){ 

      $email = trim(htmlspecialchars($_POST[$form_names['email']])); 
      $subject = trim(htmlspecialchars($_POST[$form_names['subject']])); 
      $mess = trim(htmlspecialchars($_POST[$form_names['mess']])); 

      if ($email == '' && $subject == '' && $mess == ''){ 
       // $message = "Success"; 

       $headers = "From: {$email}\r\n". 
       "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

       $current_ip = $_SERVER['REMOTE_ADDR']; 

       $html_message = nl2br($mess); 

       $sub = "CONTACT FORM: ".$subject; 

       //send email 
       $to = SITE_EMAIL; 
       $the_mess = "IP: ".$current_ip." <br /> 
         FROM: ".$email."<br /> 
         MESSAGE: <p />"."$html_message"; 

       mail($to, $sub, $the_mess, $headers); 

       $message = "<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>x</button>Thank you, your message has been sent successfully.</div>";  

      } else { 
       $message = "<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'>x</button>Please complete all required fields.</div>"; 
      } 

     } 

和形式的郵件形式:發送不工作

<form action="<?php echo $location; ?>" method="post" class="form-horizontal" enctype="multipart/form-data"> 
<label for="subject">Choose Department:</label><br> 
        <select id="subject" name="<?php echo $form_names['subject']; ?>" class="form-control"> 
         <option value="activation">Account activation</option> 
         <option value="suspension">Account suspension</option> 
         <option value="auctions">Auctions</option> 
         <option value="complaint">Complaints</option> 
         <option value="others">Others</option> 
        </select> 
      <br /> 
      <label for="email">Email Address</label> 
        <input type="text" class="form-control" name="<?php echo $form_names['email']; ?>" autocomplete="off" value="<?php echo htmlspecialchars($email); ?>" placeholder="Enter your Email Address"> 
      <br /> 
      <label for="email">Please describe your problem</label> 
      <textarea type="text" class="form-control" style="height:111px;" name="<?php echo $form_names['mess']; ?>" placeholder="Your Message" required="required"><?php echo htmlspecialchars($mess); ?></textarea> 
      <input class="btn btn-danger" type="submit" name="submit" value="Send Message" /> 
</form> 

當我提交表單,它輸出的第二$message

請填寫所有必填字段。

我在這裏找不到問題。我試過print_r(error_get_last());,它沒有顯示任何錯誤。任何幫助將非常感激。非常感謝你!

+0

如果一切都是空的,你存儲它,否則你顯示錯誤... – GolezTrol

回答

4

您的條件是if ($email == '' && $subject == '' && $mess == ''){,這意味着郵件僅在全部爲的字段爲空時發送。 我假設正確的條件應該像if ($email != '' && $subject != '' && $mess != ''){