我的联系表格不会发送电子邮件。我对表单控件不太熟悉,因此可能是导致问题的原因。当我提交表单时,没有错误消息。谢谢你的时间。有了php,我尝试在邮件功能之前添加并删除'@',没有运气。
以下是html表单的代码:
<div class="contact-form">
<h2>Contact Us</h2>
<form method="post" action="contactsent.php">
<div>
<span>name</span>
<span><input type="username" class="form-control" id="name"></span>
</div>
<div>
<span>e-mail</span>
<span><input type="email" class="form-control" id="email"></span>
</div>
<div>
<span>message</span>
<span>
<textarea name="userMsg"> </textarea>
</span>
</div>
<div>
<label class="fa-btn btn-1 btn-1e"><input type="submit" value="Send"></label>
</div>
</form>
</div>
</div>
<div class="clearfix"></div>
</div>
这是php文件(contactsent.php)(我已删除了我的电子邮件):
$email_to = "[myname@domain.com]";
$email_subject = "Contact form email";
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_POST['email'])) {
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$message = test_input($_POST["usrMsg"]);
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
ini_set('display_errors', 'on');
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
}
?>
<!-- Show this message when the submit button is pressed. -->
Thanks!