2 /** @package verysimple::Email */
5 * Object representation of an Email recipient
7 * @package verysimple::Email
8 * @author VerySimple Inc.
9 * @copyright 1997-2007 VerySimple, Inc.
17 function __construct($email, $name = "")
20 $this->Email
= $email;
21 $this->RealName
= $name != "" ?
$name : $email;
28 * Returns true if the provided email address appears to be valid.
29 * This does not determine if the address is actually legit, only
30 * if it is formatted properly
33 * string email address to validate
34 * @return bool 1 (true) if $email is valid, 0 (false) if not
36 static function IsEmailInValidFormat($email)
38 return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,25})$/i", $email);
42 * Parses an address in the either format:
43 * "Real Name <email@address.com>" or "email@address.com"
50 $pair = explode("<", $val);
52 if (isset($pair [1])) {
53 $this->RealName
= trim($pair [0]);
54 $this->Email
= trim(str_replace(">", "", $pair [1]));
57 $this->RealName
= $val;
60 // just in case there was no realname
61 if ($this->RealName
== "") {
62 $this->RealName
= $this->Email
;
67 * Returns true if $this->Email appears to be a valid email
71 function IsValidEmail()
73 return Recipient
::IsEmailInValidFormat($this->Email
);