2014-10-17 91 views
0

我已經託管了該網站,並且已經創建了表單和PHP,但我無法獲取表單來實際發送電子郵件。我很確定我正確地列出了所有的變量。表單確實提交,在用戶提交某些內容後彈出提示並且表單未顯示,但我從未收到該電子郵件。這裏是我的代碼:無法讓PHP郵件()正常工作

<?php 
if (isset($_REQUEST['email']) && isset($_REQUEST['fullname'])) { 

//Email information 
$admin_email = 'myemail.hotmail.co.uk'; 
$fullname = $_REQUEST['fullname']; 
$email = $_REQUEST['email']; 
$phone = $_REQUEST['phone']; 
$followup = $_REQUEST['followup']; 
$comment = $_REQUEST['comment']; 

//send email 
mail($admin_email, $fullname, $comment, 'From: ' . $email . 'Phone: ' . $phone . 'Follow up? ' . $followup); 

//Email response 
$contactThanks = "Thank you for contacting us!"; 
echo "<script type='text/javascript'>alert('$contactThanks');</script>"; 
} 

//if 'email' variable is not filled out, display the form 
else { 
?> 

<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'> 
    <table class='contactForm'> 
     <tr> 
      <td><label for='fullname'>*Full Name:</label></td> 
      <td><input type='text' name='fullname' id='fullname' /></td> 
     </tr> 
     <tr> 
      <td><label for='email'>*Email:</label></td> 
      <td><input type='text' name='email' id='email' /></td> 
     </tr> 
     <tr> 
      <td><label for='phone'>Phone:</label></td> 
      <td><input type='tel' name='phone' id='phone' /></td> 
     </tr> 
     <tr> 
      <td><label for='followup'>Follow Up:</label></td> 
      <td><input type='text' name='followup' id='followup' /></td> 
     </tr> 
     <tr> 
      <td><label for='comments'>Comments:</label></td> 
      <td><textarea type='text' name='comments' id='comments'></textarea></td> 
     </tr> 
     <tr> 
      <td id='inputButtons' colspan='2'> 
       <input type='submit' value='Submit' id='submit'/> 
       <input type='reset' value='Reset' id='reset'/> 
      </td> 
     </tr> 
    </table> 
</form> 
<?php 
} 
?> 

任何人都可以看到爲什麼這是行不通的?謝謝。

+0

提供您要發送的輸入信息..管理員電子郵件格式錯誤$ admin_email ='myemail.hotmail.co.uk'; – 2014-10-17 08:45:33

+0

是啊對不起,這是一個枯燥的工作,我刪除了我的實際電子郵件與替代郵政,在我的代碼中它的格式正確。 – 2014-10-17 09:03:40

回答

0

將郵件函數的返回值分配給一個變量,並檢查郵件是否實際發送。例如:

$sent = mail($admin_email, $fullname, $comment, 'From: ' . $email . 'Phone: ' . $phone . 'Follow up? ' . $followup); 

if ($sent) { 
    // thanks, mail sent 
} else { 
    // error, mail failed to send 
} 

我懷疑你沒有一臺郵件服務器(如sendmail)在服務器上安裝。

+0

更新:剛剛得到它的工作,郵件()的代碼是相同的,我不得不玩一些設置,但現在的問題是,它將所有的信息從郵件()放入「發件人」部分的電子郵件。 – 2014-10-17 09:00:47