Total members 11890 |It is currently Sat Apr 20, 2024 3:58 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Code:

<?php
   
class InvalidEmailException extends Exception {
   
      function
__construct($message, $email) {
         
$this->message = $message;
         
$this->notifyAdmin($email);
      }

      
private function notifyAdmin($email) {
         
mail("[email protected]","INVALID EMAIL",$email,"From:[email protected]");
      }

   }

   class
subscribe {
      function
validateEmail($email) {
         
try {
            if (
$email == "") {
               
throw new Exception("You must enter an e-mail address!");
            } else {
               list(
$user,$domain) = explode("@", $email);
                  if (!
checkdnsrr($domain, "MX")) {
                     
throw new InvalidEmailException("Invalid e-mail address!", $email);
                  } else {
                     return
1;
                  }
            }
         }
catch (Exception $e) {
            echo
$e->getMessage();
         }
catch (InvalidEmailException $e) {
            echo
$e->getMessage();
         }
      }

      function
subscribeUser() {
         echo
$this->email." added to the database!";
      }

   }

   
$_POST['email'] = "[email protected]";

   if (isset(
$_POST['email'])) {
      
$subscribe = new subscribe();
      if(
$subscribe->validateEmail($_POST['email']))
         
$subscribe->subscribeUser($_POST['email']);
   }

?>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Define your own exception class
 Define class helper class to check the method existance     -  
 Define class inside another class C++     -  
 how to Define abstract class in php     -  
 define final class     -  
 define a Class with a Method     -  
 Define boolean Class properties     -  
 Define Enum inside a class     -  
 Define getter and setter in php class     -  
 java abstract class,concrete class and interface     -  
 Define new namespaces in C++     -  



Topic Tags

PHP Exceptions
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com