2014-10-17 94 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