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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.