我正在尝试创建一个工作联系表单,但是当我提交表单时会显示此警告,警告:mail():无法连接到" localhost"端口25,验证您的" SMTP"和" smtp_port"在php.ini中设置或使用ini_set()。我该如何解决这个问题?任何人都可以帮忙
主要代码在这里
<?php
if(empty($_POST) === false)
{
$errors = array();
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if(empty($name) === true || empty($email) === true || empty($message) === true )
{
$errors[] = "Name, email and Message are required";
}
else if (filter_var($email, FILTER_VALIDATE_EMAIL) === false)
{
$errors[] = "This is not valid email address";
}
if (empty($errors)=== true)
{
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" ;
mail($to, $subject, $message, $headers);
header('Location : index.php?sent');
exit();
} }
?>
<!DOCTYPE html>
<html>
<head>
<title>A contact Form</title>
</head>
<body>
<div class="container" style="width: 350px; margin: 0 auto;">
<?php
if(empty($errors) === false)
{
echo "<ul>";
foreach ($errors as $error) {
echo "<li>" .$error. "</li>";
}
echo "</ul>";
}
?>
<form action="" method="POST">
<p>
<label for ="name">Name:</label> </br>
<input type="text" name="name" id="name"
<?php if (isset($_POST['name']) === true)
{ echo 'value =" ', strip_tags($_POST['name']), '"'; } ?>>
</p>
<p>
<label for ="email">Email:</label> </br>
<input type="text" name="email" id="email"
<?php if (isset($_POST['email']) === true)
{ echo 'value =" ', strip_tags($_POST['email']), '"'; } ?>>
</p>
<p>
<label for ="message">Message:</label> </br>
<textarea name="message" id ="message">
<?php if (isset($_POST['message']) === true)
{ echo strip_tags($_POST['message']); } ?> </textarea>
</p>
<p>
<input type="submit" value="Submit">
</p>
</form>
</div>
</body>
</html>