3
Contributors
3
Replies
19
Views
2 Years
Discussion Span
Last Post by enterdani
0

We aren't your code slaves. You code it, post it here, and then we critique it or help you fix errors and/or problems.

0

cant get it to work

        /*
        *   Send data using socket conneection
        */
        protected function send($msg){

            if(empty($msg)) return false;

            $this->debug_txt[] = $msg;  

            if(!fputs($this->fsock, $msg."\n")){
                $this->debug_txt[] = 'Failed to send data ';    
                return false;
            }   

            $response = null;

            while(1) {
                    $buffer = fread($this->fsock, 4096);
                    $response .= $buffer;
                    if(empty($buffer))
                        break;
            }

            //var_dump($response);

            if(!empty($response)){
                $this->debug_txt[] = 'Received response » '.$response;
            }

            return $response;
        }

        /**
        *
        *   Send helo message and check mailbox
        *
        * @return boolean
        */
        protected function ping(){

            if($this->fsock){

                stream_set_timeout($this->fsock, $this->data_timeout);

                if(!$this->send("HELO ".$this->local_host)) return;
                if(!$this->send("MAIL FROM: <".$this->local_user.'@'.$this->local_host.">")) return;

                $response = $this->send("RCPT TO: <".$this->user.'@'.$this->domain.">");

                // Get response code
                list($code, $msg) = @explode('', $response);

                $this->user = null;
                $this->domain = null;

                if ($code == '250') {
                    return true;
                }else return false;

            }else return;
        }

        /**
        * Close created socket connection
        * 
        * @return void
        */
        protected function closeSocket(){
            if($this->fsock){
                fclose($this->fsock);
                $this->fsock = false;
            }
        }


        /**
        *   Verify email address if this is exists or not
        *
        * @return boolan
        */
        public function verify($email){

            $this->email = $email;
            if(!$this->validatedEmail())
                return 0;

            if(!$this->verifyDNS())
                return 0;

            if(!$this->verifyMX())
                return 0;

            //create socket to mail host
            if(!$this->createSocket())
                return 0;

            $finalresponse = $this->ping();

            $this->closeSocket();
            return $finalresponse;

        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.