I need to send emails from PHPMailer using proxies IP addresses, I know that to do so, I need to use the fsockopen function so I can connect to the SMTP account, I also know that if I have to connect to the proxy I have to use the fsockopen function again. But using it fsockopen inside another fsockopen is not doable.
I have transparent proxy and require no authentication. I need to send this to a distant SMTP server of an external Email Service Provider.
The code I have tried :
<?php
//SMTP params
$server = 'smtp.espdomain.com';
$server_port = '25';
$username = 'smtp_login';
$password = 'smtp_pass';
//Proxy
$proxy = '1.1.1.1';
$proxy_port = 1111;
//Open connection
$socket = fsockopen($proxy, $proxy_port);
//Send command to proxy
fputs($socket, "CONNECT $server:$server_port HTTP/1.0rnHost: $proxyrnrn");
fgets($socket, 334);
//SMTP authorization
fputs($socket, "AUTH LOGINrn");
fgets($socket, 334);
fputs($socket, base64_encode($username)."rn");
fgets($socket, 334);
fputs($socket, base64_encode($password)."rn");
$output = fgets($socket, 235);
fputs($socket, "HELO $server rn");
$output = fgets($socket, 515);
?>
And it's not working I'm not sure why?
Could socat
commands help in this situation or is there any solution or alternative solution to achieve that?
I finally found the solution using socat, Kindly follow these steps :
First of all, you'll need to install
socat
on the server, you can do that simply using the command below :Then run the following
socat
command that will bindPROXY_IP:PORT
withHOST_ESP:PORT
:Then instead of making a send to the ESP through
HOST_ESP:PORT
you could just make it usingPROXY_IP:PORT
andsocat
will do the redirection automatically towardsHOST_ESP:PORT
using the output ofPROXY_IP:PORT
.Hope this helps.