我一直在努力做一个联系表格。但我的代码不起作用。我的电子邮件地址没有收到任何电子邮件。我不知道错误在哪里。有人能帮帮我吗?这是我的代码。我是Stackoverflow的新手。所以我不确定我是否正确附加了代码...
我在StackOverflow上尝试了大部分解决方案。但没有人工作。我正在使用Xampp,然后尝试在服务器上。但无论如何都没有工作。顺便说一下,我是Web开发的新手。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Contact form to email</title>
</head>
<body>
<form class="email" action="mailer.php" method="post">
<p>Name:</p>
<input type="text" name="name" />
<p>E-mail:</p>
<input type="text" name="email" />
<p>Subject:</p>
<input type="text" name="subject" />
<p>Message:</p>
<textarea name="message"></textarea></p>
<input class="send" type="submit" value="Send">
</form>
</body>
</html>
mailer.php -----------
<?php
$myemail = "zahedkamal87@gmail.com";
$name = check_input($_POST['name'], "Enter your name");
$subject = check_input($_POST['subject'], "Enter a subject");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Write your message");
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
$message = "
Name: $name
E-mail: $email
Subject: $subject
Message: $message
";
mail($myemail, $subject, $message);
header('Location: phpmail.php');
exit();
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>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>