我正在尝试编写一个执行以下操作的脚本:将用户消息打印到屏幕并将其通过电子邮件发送给他们。
这是我的代码 出于某种原因,当它是有效的电子邮件地址时,它告诉我我的电子邮件地址无效,有什么建议吗?我错过了什么?:-\
<?php
if(strtolower($_SERVER['REQUEST_METHOD']) == 'post');
$errors = null;
$success = true;
function checkEmail($email){
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
if($_POST){
$errors = array();
$to = $_POST['email'];
$subject = 'Your Comment';
$message = $_POST['message'];
$headers = 'From: blahblah69@gmail.com' . "\r\n" . 'Reply-To:
mitides.constantin@gmail.com' . "\r\n" .
'X-Mailer: PHP/' .phpversion();
if(!$to || !$message){
$errors[] ="Please fill in both a email and a message.";
} else if(!checkEmail($to) && $_POST['message'] = filter_var($_POST['message'],
FILTER_SANITIZE_STRING));{
$errors[]= print ('You did not enter a valid email, please try again.');
}
if($errors || !$_POST){
if($errors){
foreach($errors as $error){
echo $error. "<br />";
}
}
}
if(!$errors && $success){
mail($to, $subject, $message, $headers) && print($_POST['message']);
} ?>