所以,请有人帮我提供代码...我的电子邮件只是没有发送到我的电子邮件地址...非常感谢!单击按钮后,我认为我的html表单可以使用,但无法处理电子邮件发送。...对用户输入的验证(即,如果用户输入的电子邮件地址不带“ @”,则将无法验证。)有人可以吗?帮帮我.....谢谢
<?php
include("head_nav.php");
$name = "";
$email = "";
$telephone = "";
$subject = "";
$comments = "";
$error_message = "";
$email_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$string_exp = "/^[A-Za-z .'-]+$/";
$email_owner = "(email)";
if(isset($_POST["submit"])) {
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
// get input from form and sanitise it
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$telephone = test_input($_POST['telephone']);
$subject = test_input($_POST['subject']);
$comments = test_input($_POST["comments"]);
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['subject']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$name)) {
$error_message .= 'The name you entered does not appear to be valid.<br />';
}
if(strlen($subject) < 2) {
$error_message .= 'The subject you entered do not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The message you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Subject: ".clean_string($subject)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'MIME-VERSION: 1.0' . "\r\n";
$headers .='content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $email";
mail($email_owner, $subject, $email_message, $headers);
// create email headers
// $headers = 'From: '.$email_from."\r\n".
// 'Reply-To: '.$email_from."\r\n" .
// 'X-Mailer: PHP/' . phpversion();
// @mail($email, $subject, $email_message, $headers);
}
?>
<div class="content-container">
<div style="padding:5vw;">
<h2><b>Thank you for contacting us.</b></h2>
<p> We will be in touch with you very soon. </p>
</div>
<?php
include("footer.php");
?>