I am trying to write a script that does the following: Prints the users message to the screen and emails it to them as well.
here is my code For some reason it tells me my email address is invalid when it is a valid email address, any suggestions? what am i missing? :-\
<?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']);
} ?>