2017-06-14 87 views
0

我目前正在研究一個聯繫表格,它將允許用戶提交將郵件重新路由到聯繫郵件的郵件(一般的基本PHP電子郵件處理程序,目前我正在使用Brackets實時預覽來查看和編輯這個,我不知道這有什麼關係,我有這個問題PHP的電子郵件處理程序不能發郵件

HTML

<form action="mail_handler.php" method="post"> 
    <div class="w3-row-padding" style="margin:0 -16px 8px -16px"> 
     <div class="w3-half"> 
     <input class="w3-input w3-border" type="text" placeholder="Name" required name="name"> 
     </div> 
     <div class="w3-half"> 
     <input class="w3-input w3-border" type="email" placeholder="Email" required name="email"> 
     </div> 
    </div> 
    <input class="w3-input w3-border" type="text" placeholder="Message" required name="message"> 
    <button class="w3-button w3-black w3-right w3-section" type="submit"> 
     <i class="fa fa-paper-plane"></i> SEND MESSAGE 
    </button> 
    </form> 

PHP

<?php 
if(isset($_POST['submit'])){ 
$to = "[email protected]"; 
$from = $_POST['email']; 
$name = $_POST['name']; 
$subject = "Form submission"; 
$subject2 = "Copy of your form submission"; 
$message = $name . " wrote the following:" . "\n\n" . $_POST['message']; 
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message']; 

$headers = "From:" . $from; 
$headers2 = "From:" . $to; 
mail($to,$subject,$message,$headers); 
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender 
header('Location: email_confirm.html'); 
exit(); 
} 

?>

同樣,我不知道這是否只是一個括號或代碼出錯的問題。我將不勝感激一些反饋。謝謝!

編輯:這不是變量的問題,請不要標記爲缺失變量的重複。這個問題已經解決,並不是解決方案。

+1

'如果(isset($ _ POST [ '提交'])){...}'不會發生。 –

回答

0

變化這在你的HTML

<button class="w3-button w3-black w3-right w3-section" type="submit"> 

隨着

<input class="w3-button w3-black w3-right w3-section" type="submit" value="Submit" name="submit"> 
+0

謝謝你,但我仍然得到相同的帖子錯誤'無法POST /mail_handler.php' –

+0

可能會有所幫助https://stackoverflow.com/questions/26056150/cannot-post-contact-php –