我是PHP编程的新手。我找到了一个联系表单教程,但它没有用。我不知道如何解决这个问题因为我认为没有语法错误。我正在使用WAMP服务器来连接PHP。
这是PHP代码
<?php
if (isset($_POST['contact_name']) && isset($_POST['contact_email']) && isset($_POST['contact_text'])) {
$contact_name = $_POST['contact_name'];
$contact_email = $_POST['contact_email'];
$contact_text = $_POST['contact_text'];
if (!empty($contact_name) && !empty($contact_email) && !empty($contact_text)) {
$to = 'name@domain.com';
$subject = 'Custom Contact Form';
$body = $contact_name."\n".$contact_text;
$headers ='From: '.$contact_email;
if (@mail($to, $subject, $body, $headers)) {
echo 'Your form has been submitted. We\'ll contact you shortly.';
} else {
echo 'There was an error';
}
}else {
echo 'All fields are required.';
}
}
?>
这是html代码:
<form action="index.php" method="POST">
Name: <br><input type ="text" name="contact_name"><br><br>
Email address: <br><input type="text" name="contact_email"><br><br>
Message:<br>
<textarea name="contact_text" rows="6" cols="30"></textarea><br><br>
<input type="submit" value="Send">
</form>
请帮忙。