2017-06-13 65 views
0

我試圖將下拉菜單連接到我的聯繫頁面時似乎無法找到我的錯誤。我跟蹤了我的錯誤日誌,但是由於我對電子郵件不太熟悉,因此我的配置混亂了,請提前感謝您的任何建議。如何將下拉菜單連接到電子郵件 - php

<?php 

/***************** Configuration *****************/ 

// Enter your email, where you want to receive the messages. 
$contact_email_to = "EMAIL NAME"; 

// Subject prefix 
$contact_subject_prefix = " "; 

// Name too short error text 
$contact_error_name = "Name is too short or empty!"; 

// Email invalid error text 
$contact_error_email = "Please enter a valid email!"; 

// Subject too short error text 
$contact_error_subject = "Subject is too short or empty!"; 

// Message too short error text 
$contact_error_message = "Too short message! Please enter something."; 


if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { 
    // The Request must be Ajax POST, enter a message for direct access requests. 
    die('Invalid Request!'); 
} 

if(isset($_POST)) { 

    $name = filter_var($_POST["name"], FILTER_SANITIZE_STRING); 
    $email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL); 
    $company = filter_var($_POST["company"], FILTER_SANITIZE_STRING); 
    $message = filter_var($_POST["message"], FILTER_SANITIZE_STRING); 
    $subject = ($_GET["subject"]); 

    if(strlen($name)<4){ 
     die($contact_error_name); 
    } 

    if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ 
     die($contact_error_email); 
    } 

    if(strlen($company)<3){ 
     die($contact_error_subject); 
    } 

    if(strlen($message)<3){ 
     die($contact_error_message); 
    } 

    $sendemail = mail($contact_email_to, $company, $subject, $message, 
     "From: ".$name." <".$email.">" . PHP_EOL 
     ."Reply-To: ".$email . PHP_EOL 
     ."X-Mailer: PHP/" . phpversion() 
    ); 

    if($sendemail) { 
     echo 'OK'; 
    } else { 
     echo 'Could not send mail! Please check your PHP mail configuration.'; 
    } 
} 
?> 

<div class="row contact-wrap"> 
 
<div class="status alert alert-success" style="display: none"></div> 
 
<div class="col-md-8"> 
 
    <div id="sendmessage">Your message has been sent. Thank you!</div> 
 
    <div id="errormessage"></div> 
 
    <form action="" method="post" role="form" class="contactForm"> 
 
    <div class="form-group"> 
 
    <input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" /> 
 
    <div class="validation"></div> 
 
    </div> 
 
    <div class="form-group"> 
 
    <input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" /> 
 
    <div class="validation"></div> 
 
    </div> 
 
    <div class="form-group"> 
 
    <input type="text" class="form-control" name="company" id="company" placeholder="Your Company" data-rule="minlen:4" data-msg="Please enter at least 4 chars" /> 
 
    <div class="validation"></div> 
 
    </div> 
 
    <div class="form-group"> 
 
    <select name="subject" class="form-control" name="subject" id="subject"> 
 
     <option value="">---</option> 
 
     <option value="sales">Sales</option> 
 
     <option value="safety">Safety</option> 
 
     <option value="accountsP">Accounts Payable</option> 
 
     <option value="accountsR">Accounts Receivable</option> 
 
     <option value="accountsR">Human Resources</option> 
 
     <option value="accountsR">Operations</option> 
 
     <option value="accountsR">Equipment</option> 
 
     <option value="accountsR">Management</option> 
 
    </select> 
 
    </div> 
 
    <div class="form-group"> 
 
    <textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea> 
 
    <div class="validation"></div> 
 
    </div> 
 
    <div class="text-center"><button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button></div> 
 
    </form> 
 
</div>

+0

什麼是錯誤 – Rahul

回答

0

據我可以從你的解釋明白,你是無法得到subject值。問題是method。您正在使用POST方法提交表單並使用GET檢索值。

$subject = ($_GET["subject"]); 

應該

$subject = ($_POST["subject"]); 

如果您無法發送電子郵件了,你需要調試。有很多原因。我根據您的使用案例和我的理解列出少數幾個。

  1. 啓用錯誤報告 - 這將讓你看到所有的錯誤,檢查this answer
  2. 激活PHP的自定義日誌的電子郵件 - 檢查this answer
  3. 如果步驟#1和步驟#2沒有幫助,嘗試不同的郵箱 - PHPMailer或SwiftMailer
+0

我試過了,仍然出現錯誤。 –

+0

什麼是錯誤? –

+0

這是我的預定義錯誤消息'無法發送郵件!請檢查您的PHP郵件配置。' –

相關問題