2016-03-21 17 views
8

Ich muss E-Mails senden von mit Proxies IP-Adressen, weiß ich, dass ich dazu die fsockopen-Funktion verwenden muss, damit ich eine Verbindung mit dem SMTP-Konto kann Ich weiß, wenn ich eine Verbindung zum Proxy herstellen muss, muss ich die Funktion fsockopen erneut verwenden. Aber es in einem anderen fsockopen fsockopen ist nicht machbar.Senden von E-Mails von PHPMailer mit Proxies IP-Adressen

Ich habe transparenten Proxy und erfordern keine Authentifizierung. Ich muss dies an einen entfernten SMTP-Server eines externen E-Mail-Dienstanbieters senden.

Der Code, den ich versucht habe:

<?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); 

?> 

Und es funktioniert nicht ich, warum bin nicht sicher?

Können socat Befehle in dieser Situation helfen oder gibt es eine Lösung oder alternative Lösung, um das zu erreichen?

Antwort

2

Ich fand schließlich die Lösung mit socat, bitte die folgenden Schritte aus:

  1. Zunächst einmal müssen Sie installieren socat auf dem Server, können Sie das einfach mit dem folgenden Befehl tun:

    yum install socat 
    
  2. dann den folgenden socat Befehl ausführen, die PROXY_IP:PORT mit HOST_ESP:PORT binden:

    socat TCP4-LISTEN:proxy_port,bind=proxy_IP,fork,su=nobody TCP4:host:port,bind=proxy_IP 
    
  3. Dann anstatt, einen Sende zum ESP durch HOST_ESP:PORT konnte man es einfach machen mit PROXY_IP:PORT und socat führt die Umleitung automatisch zu HOST_ESP:PORT unter Verwendung der Ausgabe PROXY_IP:PORT.

Hoffe, das hilft.

2

Ist das nicht eine Wiederholung von your earlier question? Ich sehe nicht, dass sich viel geändert hat.

Sie verwenden den Proxy nicht korrekt (Sie können keine Sockets innerhalb von Sockets ausführen), aber PHPMailer hat keine spezielle Proxy-Unterstützung. Wenn es irgendwohin gehen würde, würde ich mir die Einstellungen in SMTPOptions ansehen, obwohl ich soweit sehe, dass PHP nur proxy support in HTTP streams anbietet, damit du SOL sein kannst. Es ist wahrscheinlich einfacher, einen lokalen Mailserver als Relay und nicht als Proxy auszuführen.

+1

Dank @Synchro für Ihre schnelle Wiederholung, nicht sicher, wie ich SOL in dieser Situation verwenden könnte, fügen Sie bitte ein Beispiel, wenn Sie können. (überprüfe mein Update). –

+0

Ähm, ich glaube nicht, dass Sie wissen, was SOL bedeutet (http://onlineslangdictionary.com/meaning-definition-of/sol) ... Entschuldigung! – Synchro

+0

Wenn Sie einen Proxy haben, sprechen Sie nicht direkt mit dem endgültigen Server (wie Sie es gerade tun). Sie stellen eine Verbindung zum Proxy her und senden Befehle an ihn * als ob * Sie mit dem realen Server gesprochen hätten. Der Proxy leitet die Befehle an den Zielserver weiter und leitet die Antworten an Sie zurück. In Systemen, die Proxies unterstützen, stellen Sie normalerweise eine Verbindung zum Proxy her und leiten das Ziel, mit dem Sie sich wirklich verbinden wollen, als zusätzlichen Wrapper um das Protokoll herum, das Sie gerade sprechen. PHP hat keine SMTP-Proxy-Unterstützung, nur HTTP, also müssten Sie Ihren eigenen Proxy-Code rollen oder eine Proxy-Bibliothek finden. – Synchro

1

Können Sie das versuchen ...

<?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 <[email protected]>'; 
$email->AddTo('Chilkat Admin','[email protected]'); 

// 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"; 
?>