2016-03-21 21 views
8

Devo inviare e-mail da PHPMailer utilizzando i proxy indirizzi IP, so che per farlo, ho bisogno di utilizzare la funzione fsockopen così posso connettermi all'account SMTP, anch'io sappi che se devo collegarmi al proxy devo usare di nuovo la funzione fsockopen. Ma usarlo fsockopen all'interno di un altro fsockopen non è fattibile.Invio di email da PHPMailer utilizzando i proxy Indirizzi IP

Ho proxy trasparente e non richiede autenticazione. Devo inviarlo a un server SMTP remoto di un provider di servizi di posta elettronica esterno.

Il codice che ho provato:

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

?> 

E non funziona io non sono sicuro perché?

I comandi socat possono aiutare in questa situazione o esiste una soluzione o una soluzione alternativa per raggiungere tale obiettivo?

risposta

2

ho finalmente trovato la soluzione con socat, Gentilmente attenersi alla seguente procedura:

  1. Prima di tutto, è necessario installare socat sul server, è possibile farlo semplicemente utilizzando il comando seguente:

    yum install socat 
    
  2. quindi eseguire il socat seguente comando che legherà PROXY_IP:PORT con HOST_ESP:PORT:

    socat TCP4-LISTEN:proxy_port,bind=proxy_IP,fork,su=nobody TCP4:host:port,bind=proxy_IP 
    
  3. Poi, invece di fare un invio alla ESP attraverso HOST_ESP:PORT si può solo fare utilizzando PROXY_IP:PORT e socat eseguirà automaticamente il reindirizzamento verso HOST_ESP:PORT utilizzando l'output di PROXY_IP:PORT.

Spero che questo aiuti.

2

Non è una ripetizione di your earlier question? Non vedo che molto è cambiato.

Non si sta utilizzando il proxy correttamente (non è possibile eseguire socket all'interno dei socket), ma PHPMailer non dispone di alcun supporto proxy specifico. Se dovesse essere ovunque, guarderei le proprietà di impostazione in SMTPOptions, anche se per quanto posso vedere PHP offre solo proxy support in HTTP streams quindi potresti essere SOL. Probabilmente è più semplice eseguire un server di posta locale da inoltrare piuttosto che da un proxy.

+1

Grazie a @Synchro per la riproduzione rapida, non sono sicuro di come potrei usare SOL in questa situazione, per favore aggiungi un esempio se puoi. (controlla il mio aggiornamento). –

+0

Um, non penso che tu sappia [cosa significa SOL] (http://onlineslangdictionary.com/meaning-definition-of/sol) ... Ci scusiamo! – Synchro

+0

Quando si ha un proxy, non si parla direttamente al server finale (come si sta tentando di fare). Ti connetti al proxy e invii comandi ad esso * come se * stavi parlando al server reale. Il proxy inoltra i comandi al server di destinazione e restituisce le risposte all'utente. Nei sistemi che supportano i proxy, si stabilisce normalmente la connessione al proxy e si passa il target a cui si desidera realmente connettersi come un ulteriore wrapper attorno a qualunque protocollo si stia parlando. PHP non ha il supporto proxy SMTP, solo HTTP, quindi è necessario eseguire il rollover del proprio codice proxy o trovare una libreria proxy. – Synchro

1

Potete provare questo ...

<?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"; 
?> 
Problemi correlati