【问题标题】:Contact form with XAMPP not working?与 XAMPP 的联系表格不起作用?
【发布时间】:2015-10-03 23:13:17
【问题描述】:

我试图在 xampp 中创建一个联系表单,但我不知道为什么表单没有发送电子邮件。即使被告知,php 表单也不会显示任何错误。我在正确的 localhost 目录中有该文件,但它不能正确执行。这是我使用的代码

<?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[] = 'That\'s not a valid email address';

    }
    if (ctype_alpha($name) === false) {

        $error[] = 'Name must only contain letters';

   }

  }

  if (empty($errors) === true) {
      mail('admin@localhost', 'Contact form', $message, 'From: ' . $email);
      header('Location: www.artfbla.org/contact.php?sent');
      exit();

  }

}

?>



<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 

if (isset($_GET['sent']) === true) {
    echo '<p>Thanks for contacting us!</p>';
} else {


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 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 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>
<?php 
}
?>


</body>
</html>

【问题讨论】:

标签: php html forms xampp


【解决方案1】:

您需要在 localhost 上设置 SMTP 服务器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-31
    • 2016-10-28
    • 2014-10-04
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多