简体   繁体   English

使用代理 IP 地址从 PHPMailer 发送电子邮件

[英]Sending emails from PHPMailer using proxies IP addresses

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.我需要使用代理 IP 地址从PHPMailer发送电子邮件,我知道这样做,我需要使用 fsockopen 函数以便我可以连接到 SMTP 帐户,我也知道如果我必须连接到代理,我必须再次使用 fsockopen 函数。 But using it fsockopen inside another fsockopen is not doable.但是在另一个 fsockopen 中使用它 fsockopen 是不可行的。

I have transparent proxy and require no authentication.我有透明代理,不需要身份验证。 I need to send this to a distant SMTP server of an external Email Service Provider.我需要将其发送到外部电子邮件服务提供商的远程 SMTP 服务器。

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.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?它不起作用我不知道为什么?

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 : 我终于找到了使用socat的解决方案,请按照以下步骤操作:

  1. First of all, you'll need to install socat on the server, you can do that simply using the command below : 首先,您需要在服务器上安装socat ,只需使用以下命令即可:

     yum install socat 
  2. Then run the following socat command that will bind PROXY_IP:PORT with HOST_ESP:PORT : 然后运行以下socat命令,它将PROXY_IP:PORTHOST_ESP:PORT绑定:

     socat TCP4-LISTEN:proxy_port,bind=proxy_IP,fork,su=nobody TCP4:host:port,bind=proxy_IP 
  3. 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 . 然后,您可以仅使用PROXY_IP:PORT使其通过HOST_ESP:PORT发送到ESP,而socat将使用HOST_ESP:PORT的输出自动将其重定向到PROXY_IP:PORT

Hope this helps. 希望这可以帮助。

Isn't this a repeat of your earlier question ? 这不是您先前问题的重复吗? I don't see that much has changed. 我看不出太大的变化。

You are not using the proxy correctly (you can't do sockets inside sockets), but PHPMailer doesn't have any specific proxy support. 您没有正确使用代理(您不能在套接字内使用套接字),但是PHPMailer没有任何特定的代理支持。 If it was going to be anywhere, I'd look at setting properties in SMTPOptions , though as far as I can see PHP only offers proxy support in HTTP streams so you may be SOL. 如果要放在任何地方,我都会在SMTPOptions中设置属性,尽管据我SMTPOptions ,PHP仅在HTTP流中提供代理支持,所以您可能是SOL。 It's probably easier to run a local mail server to relay rather than proxy. 运行本地邮件服务器进行中继而不是代理可能更容易。

Can you Try this... 你可以试试这个吗?

<?php

//  The mailman object is used for sending and receiving email.
$mailman = new COM("Chilkat.MailMan2");

//  Any string argument automatically begins the 30-day trial.
$success = $mailman->UnlockComponent('30-day trial');
if ($success != true) {
    print 'Component unlock failed' . "\n";
    exit;
}

//  To connect through an HTTP proxy, set the HttpProxyHostname
//  and HttpProxyPort properties to the hostname (or IP address)
//  and port of the HTTP proxy.  Typical port numbers used by
//  HTTP proxy servers are 3128 and 8080.
$mailman->HttpProxyHostname = 'www.my-http-proxy.com';
$mailman->HttpProxyPort = 3128;

//  Important:  Your HTTP proxy server must allow non-HTTP
//  traffic to pass.  Otherwise this does not work.

//  Set the SMTP server.
$mailman->SmtpHost = 'smtp.chilkatsoft.com';

//  Set the SMTP login/password (if required)
$mailman->SmtpUsername = 'myUsername';
$mailman->SmtpPassword = 'myPassword';

//  Create a new email object
$email = new COM("Chilkat.Email2");

$email->Subject = 'This is a test';
$email->Body = 'This is a test';
$email->From = 'Chilkat Support <support@chilkatsoft.com>';
$email->AddTo('Chilkat Admin','admin@chilkatsoft.com');

//  Call SendEmail to connect to the SMTP server via the HTTP proxy and send.
//  The connection (i.e. session) to the SMTP server remains
//  open so that subsequent SendEmail calls may use the
//  same connection.
$success = $mailman->SendEmail($email);
if ($success != true) {
    print $mailman->lastErrorText() . "\n";
    exit;
}

//  Some SMTP servers do not actually send the email until
//  the connection is closed.  In these cases, it is necessary to
//  call CloseSmtpConnection for the mail to be  sent.
//  Most SMTP servers send the email immediately, and it is
//  not required to close the connection.  We'll close it here
//  for the example:
$success = $mailman->CloseSmtpConnection();
if ($success != true) {
    print 'Connection to SMTP server not closed cleanly.' . "\n";
}

print 'Mail Sent!' . "\n";
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM