使用代理IP地址从PHPMailer发送电子邮件 [英] Sending emails from PHPMailer using proxies IP addresses

查看:1119
本文介绍了使用代理IP地址从PHPMailer发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用代理IP地址从 PHPMailer 发送电子邮件,我知道这样做,我需要使用fsockopen函数,所以我可以连接到SMTP帐户,我也知道如果我必须连接到代理,我必须再次使用fsockopen函数。但是使用它在另一个fsockopen内的fsockopen是不可行的。

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.

我有透明代理,不需要身份验证。我需要将其发送到外部电子邮件服务提供商的远程SMTP服务器。

I have transparent proxy and require no authentication. I need to send this to a distant SMTP server of an external Email Service Provider.

我尝试的代码:

<?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.0\r\nHost: $proxy\r\n\r\n");
    fgets($socket, 334);

    //SMTP authorization  
    fputs($socket, "AUTH LOGIN\r\n");
    fgets($socket, 334);

    fputs($socket, base64_encode($username)."\r\n");
    fgets($socket, 334);

    fputs($socket, base64_encode($password)."\r\n");
    $output = fgets($socket, 235);

    fputs($socket, "HELO $server \r\n"); 
    $output = fgets($socket, 515);

?>

它不工作我不知道为什么?

And it's not working I'm not sure why?

可能 socat 命令在这种情况下有帮助,还是有任何解决方案或替代解决方案来实现?

Could socat commands help in this situation or is there any solution or alternative solution to achieve that?

推荐答案

我终于找到了使用 socat ,请按照以下步骤操作:

I finally found the solution using socat, Kindly follow these steps :


  1. 首先,您将需要要在服务器上安装 socat ,可以使用以下命令:

  1. First of all, you'll need to install socat on the server, you can do that simply using the command below :

yum install socat


  • 然后运行以下 socat 命令将绑定 PROXY_IP:PORT HOST_ESP:PORT

  • Then run the following socat command that will bind PROXY_IP:PORT with HOST_ESP:PORT :

    socat TCP4-LISTEN:proxy_port,bind=proxy_IP,fork,su=nobody TCP4:host:port,bind=proxy_IP
    


  • 国王通过 HOST_ESP:PORT 发送到ESP,您可以使用 PROXY_IP:PORT socat 将自动执行重定向到 HOST_ESP:PORT / strong>使用 PROXY_IP:PORT 的输出。

  • Then instead of making a send to the ESP through HOST_ESP:PORT you could just make it using PROXY_IP:PORT and socat will do the redirection automatically towards HOST_ESP:PORT using the output of PROXY_IP:PORT.

    希望这有帮助。

    这篇关于使用代理IP地址从PHPMailer发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆