问题
I'm using PHPMailer and it uses fsockopen
to access the SMTP server.
But the machine has two IPs with different reverse DNS records. So in email headers I got the following:
Received: from one-server.tld (HELO another-server.tld) ...
I need to hide one-server.tld
in favor of another-server.tld
. But I need both IPs with their current RDNS settings.
回答1:
I think its not possible using fsockopen
. But its possible in curl
, fopen
and stream
functions. What you need is stream_socket_client() function.
Here are some ways to achieve it.
Using context parameters which can be used in fopen function family and stream function family. See the example.
$opts = array( 'socket' => array( 'bindto' => '192.168.0.100:0', ), ); // create the context... $context = stream_context_create($opts); $contents = fopen('http://www.example.com', 'r', false, $context);
Also stream_socket_client
$fp = stream_socket_client("tcp://www.example.com:80", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $opts); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { fwrite($fp, "GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n"); while (!feof($fp)) { echo fgets($fp, 1024); } fclose($fp); }
Using socket_bind. PHP.NET got a simple example here.
来源:https://stackoverflow.com/questions/8967947/can-i-open-socket-in-php-from-a-specific-ip-if-the-machine-has-two-ips