2016-04-19 80 views
1

任何人都可以指出我在哪裏得到這種形式是錯誤的?而不是能夠回覆發件人的「電子郵件」,我得到服務器電子郵件。PHP郵件回覆發件人而不是服務器郵件

這裏是PHP代碼:

<?php 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $message = $_POST['message']; 
    $from = 'From: business.com'; 
    $to = '[email protected]'; 
    $subject = 'A new Message from your website business.com'; 
    $human = $_POST['human']; 
    $headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: ' . $email . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

    $body = "From: $name\n E-Mail: $email\n Message:\n $message"; 

    if ($_POST['submit']) { 
    if ($name != '' && $email != '') { 
     if ($human == '4') {     
      if (mail ($to, $subject, $body, $from)) { 
      echo '<p>Your message has been sent!</p>'; 
     } else { 
      echo '<p>Something went wrong, go back and try again!</p>'; 
     } 
    } else if ($_POST['submit'] && $human != '4') { 
     echo '<p>You answered the anti-spam question incorrectly!</p>'; 
    } 
    } else { 
     echo '<p>You need to fill in all required fields!!</p>'; 
    } 
} 
?> 

這裏是HTML

<form method="post" action="contact.php" target="contactIframe" name="contact"> 
    <label>Name</label> 
    <input name="name" placeholder="Type Here"> 
    <label>Email</label> 
    <input name="email" type="email" placeholder="Type Here"> 
    <label>Message</label> 
    <textarea name="message" placeholder="Type Here"></textarea></br> 
    <label>*What is 2+2? (Anti-spam)</label> 
    <input name="human" placeholder="Type Here"></br></br> 
    <input id="submit" name="submit" type="submit" value="Submit"> 
    <input type="button" name="reset_form" value="Clear" onclick="this.form.reset();"> 
</form> 

謝謝大家

回答

1

您的郵件功能沒有$headers作爲附加頭。該代碼應該是...

if ($human == '4') {     
    if (mail ($to, $subject, $body, $headers)) { 
     echo '<p>Your message has been sent!</p>'; 
    } 
} 

裁判:PHP Mail Function

+0

哇...你說得對,我已經錯過了,但是,仍然有某處編輯爲除了$頭正在觸發回顯錯誤信息 –

+0

檢查是否有代碼中定義的'$ body' ...如果存在,則檢查服務器'error_log'。 –

+0

嗨Gopakumar,感謝您的幫助,$ body標籤位於代碼中,您可以在上面看到,但我不確定是否可以訪問服務器錯誤日誌。 –

相關問題