我无法在代码中找到错误。我的PHP代码在我的index.html文件中。我无法从我的静态网页发送消息。
HTML代码:<div class="col-md-6">
<form action="index.html" method="POST" class="contact-form" role="form">
<input type="text" class="form-control" id="fname" name="fname" placeholder="Your Full Name">
<input type="email" class="form-control" id="email" name="email" placeholder="Your E-mail">
<input type="text" class="form-control" id="subj" name="subj" placeholder="Your Subject">
<textarea id="mssg" name="mssg" placeholder="Your Message" class="form-control" rows="10"></textarea>
<input class="btn btn-main btn-lg" type="submit" id="submit" name="submit" data-loading-text="<i class='fa fa-spinner fa-spin'></i> Sending...">
</form>
</div>
PHP代码:<?php
if (isset($_POST['submit'])) {
$to = 'email@company.com';
$siteName = 'http://www.website.com';
$name = $_POST['fname'];
$mail = $_POST['email'];
$subject = $_POST['subj'];
$message = $_POST['mssg'];
$mailSub = '[Contact] [' . $siteName . '] '.$subject;
$body = 'Sender Name: ' . $name . "'n'n";
$body .= 'Sender Mail: ' . $mail . "'n'n";
$body .= 'Message Subject: ' . $subject . "'n'n";
$body .= 'Message: ' . $message;
$header = 'From: ' . $mail . "'r'n";
$header .= 'To: ' . $to . "'r'n";
mail($to, $mailSub, $body, $header);
}else{
echo '0';
}
?>
我收到一个错误,每次我试图通过我的网站发送消息。谢谢你!
如果您没有指示系统将.html
文件视为PHP,则查看action="index.html"
可能会出现问题。
如果没有,那么您需要将其更改为.php
文件扩展名并重命名当前文件以适应它。然后将操作值更改为指向该文件。
<form action="script.php" method="post">
-
script.php
是当前的PHP处理程序。