public function validate()
    {
        $result = parent::validate();
        $checkEmail = [
            'EmailAddress' => 'EMAILADDRESSINVALID',
            'EmailFrom' => 'EMAILFROMINVALID',
            'EmailReplyTo' => 'EMAILREPLYTOINVALID',
        ];
        foreach ($checkEmail as $check => $translation) {
            if ($this->$check) {
                //may be a comma separated list of emails
                $addresses = explode(',', $this->$check);
                foreach ($addresses as $address) {
                    $trimAddress = trim($address);
                    if ($trimAddress && !Email::is_valid_address($trimAddress)) {
                        $error = _t(
                            __CLASS__.".$translation",
                            "Invalid email address $trimAddress"
                        );
                        $result->addError($error . " ($trimAddress)");
                    }
                }
            }
        }

        // if there is no from address and no fallback, you'll have errors if this isn't defined
        if (!$this->EmailFrom && empty(Email::getSendAllEmailsFrom()) && empty(Email::config()->get('admin_email'))) {
            $result->addError(_t(__CLASS__.".EMAILFROMREQUIRED", '"Email From" address is required'));
        }
        return $result;
    }
public function validate()
    {
        $result = parent::validate();
        $checkEmail = [
            'EmailAddress' => 'EMAILADDRESSINVALID',
            'EmailFrom' => 'EMAILFROMINVALID',
            'EmailReplyTo' => 'EMAILREPLYTOINVALID',
        ];
        foreach ($checkEmail as $check => $translation) {
            if ($this->$check) {
                //may be a comma separated list of emails
                $addresses = explode(',', $this->$check);
                foreach ($addresses as $address) {
                    $trimAddress = trim($address);
                    if ($trimAddress && !Email::is_valid_address($trimAddress)) {
                        $error = _t(
                            __CLASS__.".$translation",
                            "Invalid email address $trimAddress"
                        );
                        $result->addError($error . " ($trimAddress)");
                    }
                }
            }
        }

        // if there is no from address and no fallback, you'll have errors if this isn't defined
        if (!$this->EmailFrom && empty(Email::getSendAllEmailsFrom()) && empty(Email::config()->get('admin_email'))) {
            $result->addError(_t(__CLASS__.".EMAILFROMREQUIRED", '"Email From" address is required'));
        }
        return $result;
    }
public function validate ( ) { $ result = parent :: validate ( ) ; $ checkEmail = [ 'EmailAddress' => 'EMAILADDRESSINVALID' , 'EmailFrom' => 'EMAILFROMINVALID' , 'EmailReplyTo' => 'EMAILREPLYTOINVALID' , ] ; foreach ( $ checkEmail as $ check => $ translation ) { if ( $ this -> $ check ) { //may be a comma separated list of emails $ addresses = explode ( ',' , $ this -> $ check ) ; foreach ( $ addresses as $ address ) { $ trimAddress = trim ( $ address ) ; if ( $ trimAddress && ! Email :: is_valid_address ( $ trimAddress ) ) { $ error = _t ( __CLASS__ . ".$translation" , "Invalid email address $trimAddress" ) ; $ result -> addError ( $ error . " ($trimAddress)" ) ; } } } } // if there is no from address and no fallback, you'll have errors if this isn't defined if ( ! $ this -> EmailFrom && empty ( Email :: getSendAllEmailsFrom ( ) ) && empty ( Email :: config ( ) -> get ( 'admin_email' ) ) ) { $ result -> addError ( _t ( __CLASS__ . ".EMAILFROMREQUIRED" , '"Email From" address is required' ) ) ; } return $ result ; }
Validate that valid email addresses are being used

@return ValidationResult
Validate that valid email addresses are being used