我使用的代码与这个 stackoverflow 问题Simple PHP Contact Form Not Sending相同的代码有同样的问题,除了他们的问题是通过检查他们的垃圾邮件框来解决的,因为我的是空的。我正在运行 Ubuntu,已安装 PHP,从 Apache 2 在本地运行网页。我唯一的提示是 Chrome 加载可能会加载一分钟,然后我会返回一个“谢谢”PHP 页面。我应该先尝试什么?
html
<form action="contactus.php" method="POST" class="create">
<fieldset>
<legend align="center">Please fill out details below and click "Submit"</legend>
<div>
<label for="fullname" class="fixedwidth">Full Name</label>
<input type="text" name="fullname" id="fullname" class="input2"/>
</div><br/>
<div>
<label for="email" class="fixedwidth">Email</label>
<input type="text" name="email" id="email" class="input2"/>
</div><br/>
<div>
<label for="subject" class="fixedwidth">Subject</label>
<input type="text" name="subject" id="subject" class="input2"/>
</div><br/>
<div>
<label for="details" class="fixedwidth">Body</label>
<textarea id="details" name="details" cols="62" rows="20"></textarea>
</div>
<div class="buttonarea">
<input type="submit" name="submit" id="submit" value="Submit"/>
</div>
</fieldset>
</form>
php
<?php
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$details = $_POST['details'];
$formcontent = "From: $fullname \n Message: $details";
$recipient = "johndoe1@email.com";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>