954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Port Forwarding?

My web host has closed off port 25 to user code as it was being used by other users to send spam. Unfortunately, I have the following code which I use to validate email addresses:

function fixed_gethostbyname ($host) {
    // Try the lookup as normal...
    $ip = gethostbyname($host);
    // ...but if it fails, FALSE is returned instead of the unresolved host
    if ($ip != $host) { return $ip; } else return false;
}
function verifyemail() {
        global $domain, $username, $email, $HTTP_HOST;
        $domainexists = fixed_gethostbyname($domain);
        $mxexists = checkdnsrr("$domain.", 'MX');
        if (!$domainexists && !$mxexists) return false;
        else if (!$mxexists) return false;
        else {
                if (getmxrr($domain, $MXHost))  {
                        $ConnectAddress = $MXHost[0];
                } else {
                        $ConnectAddress = $domain;
                }
                $Connect = @fsockopen ( $ConnectAddress, 25 );
                if ($Connect) {
                        if (ereg("^220", $Out = fgets($Connect, 1024))) {
                                fputs ($Connect, "HELO $HTTP_HOST\r\n");
                                $Out = fgets ( $Connect, 1024 );
                                fputs ($Connect, "MAIL FROM: <{$email}>\r\n");
                                $From = fgets ( $Connect, 1024 );
                                fputs ($Connect, "RCPT TO: <{$email}>\r\n");
                                $To = fgets ($Connect, 1024);
                                fputs ($Connect, "QUIT\r\n");
                                fclose($Connect);
                                if (!ereg ("^250", $From) || !ereg ( "^250", $To )) {
                                        return false;
                                }
                        } else {
                                return false;
                        }
                } else {
                        return false;
                }
        }
        return true;
}

Yes I know there's better code, but this does the trick for me well enough for now. The problem is that it doesn't do the trick any more, because port 25 is closed.

Is there a way within PHP to have my message leave on another port, say 625, and arrive at port 25 at the other end?

DiMono
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

fsockopen is setting the port number for you to write to. If you change it from 25 to 625 (assuming that is what your hosting company accepts emails on) then it will be delivered. You don't have to worry about the destination port.

phpstan
Newbie Poster
14 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: