Here I am trying to give an error message in my index.php from the file emailValidation.php. I am trying to use $emailMessage which is located in emailValidation.php.
Here is the error I am getting: Notice : Undefined variable: emailMessage in D:\XAMPP\htdocs\magebit_test\index.php on line 49
this is index.php
<?php
include 'database/emailValidation.php';
include 'database/subscribers.php';
$subscribers= new subscribers();
$subscribers->insertSubscribers();
$validation = new emailValidation();
$validation->validation();
// include 'database/viewSubscribers.php';
?>
<span><?php echo $emailMessage ?></span>
This is my emailValidation.php
<?PHP
class emailValidation {
function checkemail($email) {
return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email) ) ? FALSE : TRUE;
}
function columbia($email){
return (!preg_match("/@([\w-])+\.co$/mi", $email)) ? FALSE : TRUE;
}
function validation(){
if(isset($_POST['emailSubmit'])){
if (empty($_POST["emailText"])) {
$emailMessage = "Email is required";
} else {
$email = $_POST["emailText"];
if (!checkemail($email) || columbia($email)) {
$emailMessage = "Invalid email format";
}
}
}
}
}