我再次尝试使用简单的联系表单发送电子邮件,
那就是代码:
<?php
if (empty($_POST) === false) {
$errors = array();
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
echo $name,' ', $email, ' ', $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) {
$errors ='name must only contain letters';
}
}
if (empty($errors) ===true) {
mail('talrod160@gmail.com','contact form','$message','From:' . $email);
header('location:index.php?sent');
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>A contact form</title>
</head>
<body>
<?php
if (isset($GET ['sent']) === true) {
echo '<p>Thanks for contact 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 ($_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="', ($_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>
现在我遇到了这个问题而且无法理解为什么,
解析错误:语法错误,意外'&lt;'在第46行的D:\ xampp \ htdocs \ contact_form \ index.php
并希望有人能解释我关于foreach循环
感谢。
答案 0 :(得分:1)
xArr[i*2+1]
可能应为<p>Thanks for contact us<?/p>