-1
有問題,我是新來的PHP,我試圖做一個基本的聯繫表格。我已經創建了表單,而且就我所知,PHP看起來是正確的。但是,該電子郵件似乎並未發送。用PHP電子郵件形式
形式可以通過點擊頂部附近的「聯繫模態測試」按鈕,在這裏http://abenjamin765.github.io/pushpin2/看到。
我錯過了什麼嗎?
HTML:
<div class="modal fade" id="contact">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" name="contactform" method="post" action="php/contact.php" role="form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Get a Quote</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="contact-name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="contact-name" placeholder="First and Last name">
</div>
</div>
<div class="form-group">
<label for="contact-email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="contact-email" placeholder="[email protected]">
</div>
</div>
<div class="form-group">
<label for="contact-message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea type="text" rows="4" class="form-control" id="contact-message" placeholder="Write a message..."></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
,這是我的PHP ...
<?php
/* Set e-mail recipient */
$myemail = "[email protected]";
/* Check all form inputs using check_input function */
$name = check_input($_POST['contact-name'], "Your Name");
$email = check_input($_POST['contact-email'], "Your E-mail Address");
$message = check_input($_POST['contact-message'], "Your Message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$subject = "New lead from $name!";
$message = "
Someone has sent you a message using your contac form:
Name: $name
Email: $email
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: thankyou.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Please try again</p>
</body>
</html>
<?php
exit();
}
?>
您是否打擾查找錯誤? '405方法不Allowed'意味着github.io已經不允許了'POST'協議,或者也許'郵件()'函數,因爲Github上不希望運行的垃圾郵件腳本的惡意腳本這是可以理解的。他們可能完全不允許執行PHP腳本(這可能是最可能的原因)。找到一個web服務器來測試這個特定的代碼。 – sjagr 2014-10-03 01:30:26
退房http://www.checkupdown.com/status/E405.html – wavemode 2014-10-03 01:33:31
我做到了,謝謝你......看起來像它的工作MAMP,但是電子郵件仍然不發送。 – 2014-10-03 02:31:20