2009-08-05 25 views
16

Tengo problemas para enviar un correo electrónico con la clase PHPMailer, pero funciona con PEAR Mail :: factory.Problema con la autenticación SMTP en PHP utilizando PHPMailer, con Pear Mail funciona

Supongo que el problema es con la autenticación SMTP, pero no pude encontrar el problema.

El código de problema es:

<?php 
require("class.phpmailer.php"); 

$mail = new PHPMailer(); 

$mail->IsSMTP();  // set mailer to use SMTP 
$mail->Host = 'mail.xxx.com.br'; // my host here 
$mail->SMTPAuth = true;  // turn on SMTP authentication 
$mail->Username = '[email protected]'; // a valid email here 
$mail->Password = '***'; // the password from email 
$mail->From = '[email protected]'; 
$mail->SMTPDebug = true; 
$mail->AddReplyTo('[email protected]', 'Test'); 

$mail->FromName = 'Test SMTP'; 
$mail->AddAddress('[email protected]', '[email protected]'); 

$mail->Subject = 'Test SMTP'; 
$mail->IsHTML(true); 
$mail->Body = '<b>Teste</b><br><h1>teste 2</h1>'; 
//$mail->Send(); 

if(!$mail->Send()) 
{ 
    echo "Message could not be sent. <p>"; 
    echo "Mailer Error: " . $mail->ErrorInfo; 
    exit; 
} 

?> 

El código con PEAR que funciona es:

<?php 
include('Mail.php'); 
include('Mail/mime.php'); 

$text = 'Versao em texto'; 
$html = '<html><body>Versao de email em <b>HTML</b></body></html>'; 
$crlf = "\n"; 
$hdrs = array(
       'From' => '[email protected]', 
       'Subject' => 'Test - mail.php' 
      ); 

$mime = new Mail_mime($crlf); 

$mime->setTXTBody($text); 
$mime->setHTMLBody($html); 

$body = $mime->get(); 
$hdrs = $mime->headers($hdrs); 

$mail = Mail::factory('smtp', 
    array ('host' => 'mail.xxx.com.br', 
    'debug'=> true, 
    'auth' => true, 
    'username' => '[email protected]', 
    'password' => '***')); 

$mail->send('[email protected]', $hdrs, $body); 
?> 

Cuando ejecuto el código con el problema de depuración activado (SMTPDebug = True) Tengo:

SMTP -> FROM SERVER: 

SMTP -> get_lines(): $data was "" 

SMTP -> get_lines(): $str is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300 

" 

SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300 

" 

SMTP -> get_lines(): $data was "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300 

" 
SMTP -> get_lines(): $str is "220-We do not authorize the use of this system to transport unsolicited, 
" 

SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300 

220-We do not authorize the use of this system to transport unsolicited, 

" 

SMTP -> get_lines(): $data was "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300 

220-We do not authorize the use of this system to transport unsolicited, 

" 

SMTP -> get_lines(): $str is "220 and/or bulk e-mail. 

" 

SMTP -> get_lines(): $data is "220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300 

220-We do not authorize the use of this system to transport unsolicited, 

220 and/or bulk e-mail. 

" 

SMTP -> FROM SERVER: 

220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300 

220-We do not authorize the use of this system to transport unsolicited, 

220 and/or bulk e-mail. 

SMTP -> ERROR: EHLO not accepted from server: 220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Wed, 05 Aug 2009 10:00:48 -0300 

220-We do not authorize the use of this system to transport unsolicited, 

220 and/or bulk e-mail. 


SMTP -> get_lines(): $data was "" 

SMTP -> get_lines(): $str is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

" 

SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

" 

SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

" 

SMTP -> get_lines(): $str is "250-SIZE 20971520 

" 

SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 
250-SIZE 20971520 

" 

SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 
250-SIZE 20971520 

" 

SMTP -> get_lines(): $str is "250-PIPELINING 

" 

SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

250-SIZE 20971520 

250-PIPELINING 

" 

SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

250-SIZE 20971520 

250-PIPELINING 

" 

SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN 

" 

SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

250-SIZE 20971520 

250-PIPELINING 

250-AUTH PLAIN LOGIN 

" 

SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

250-SIZE 20971520 

250-PIPELINING 

250-AUTH PLAIN LOGIN 

" 

SMTP -> get_lines(): $str is "250-STARTTLS 

" 

SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

250-SIZE 20971520 

250-PIPELINING 

250-AUTH PLAIN LOGIN 

250-STARTTLS 

" 

SMTP -> get_lines(): $data was "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

250-SIZE 20971520 

250-PIPELINING 

250-AUTH PLAIN LOGIN 

250-STARTTLS 

" 

SMTP -> get_lines(): $str is "250 HELP 

" 

SMTP -> get_lines(): $data is "250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

250-SIZE 20971520 

250-PIPELINING 

250-AUTH PLAIN LOGIN 

250-STARTTLS 

250 HELP 

" 

SMTP -> FROM SERVER: 

250-orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

250-SIZE 20971520 

250-PIPELINING 

250-AUTH PLAIN LOGIN 

250-STARTTLS 

250 HELP 

SMTP -> get_lines(): $data was "" 

SMTP -> get_lines(): $str is "250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

" 

SMTP -> get_lines(): $data is "250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 

" 

SMTP -> ERROR: AUTH not accepted from server: 250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 


SMTP -> get_lines(): $data was "" 

SMTP -> get_lines(): $str is "503 AUTH command used when not advertised 

" 

SMTP -> get_lines(): $data is "503 AUTH command used when not advertised 

" 

SMTP -> FROM SERVER: 

503 AUTH command used when not advertised 

SMTP -> ERROR: RSET failed: 503 AUTH command used when not advertised 


Message could not be sent. <p>Mailer Error: SMTP Error: Could not connect to SMTP host. 

Un nd el resultado de depuración del código de PEAR Mail es:

DEBUG: Recv: 220-orion.bommtempo.net.br ESMTP Exim 4.69 #1 Tue, 04 Aug 2009 19:37:10 -0300 

DEBUG: Recv: 220-We do not authorize the use of this system to transport unsolicited, 

DEBUG: Recv: 220 and/or bulk e-mail. 

DEBUG: Send: EHLO localhost 


DEBUG: Recv: 250-orion.bommtempo.net.br Hello localhost [200.155.129.6] 

DEBUG: Recv: 250-SIZE 20971520 

DEBUG: Recv: 250-PIPELINING 

DEBUG: Recv: 250-AUTH PLAIN LOGIN 

DEBUG: Recv: 250-STARTTLS 

DEBUG: Recv: 250 HELP 

DEBUG: Send: STARTTLS 


DEBUG: Recv: 220 TLS go ahead 

DEBUG: Send: EHLO localhost 


DEBUG: Recv: 250-orion.bommtempo.net.br Hello localhost [200.155.129.6] 

DEBUG: Recv: 250-SIZE 20971520 

DEBUG: Recv: 250-PIPELINING 

DEBUG: Recv: 250-AUTH PLAIN LOGIN 

DEBUG: Recv: 250 HELP 

DEBUG: Send: AUTH LOGIN 


DEBUG: Recv: 334 VXNlcm5hbWU6 

DEBUG: Send: c2lzdGVtYWFkbWluQGJvbW10ZW1wby5jb20uYnI= 


DEBUG: Recv: 334 UGFzc3dvcmQ6 

DEBUG: Send: RVkyYVM4YnpMNU5k 


DEBUG: Recv: 235 Authentication succeeded 

DEBUG: Send: MAIL FROM: 


DEBUG: Recv: 250 OK 

DEBUG: Send: RCPT TO: 


DEBUG: Recv: 250 Accepted 

DEBUG: Send: DATA 


DEBUG: Recv: 354 Enter message, ending with "." on a line by itself 

DEBUG: Send: MIME-Version: 1.0 

From: [email protected] 

Subject: Teste de mail - mail.php 

Content-Type: multipart/alternative; 
    boundary="=_b3c5407ccf494306d78fbb35800efe65" 


--=_b3c5407ccf494306d78fbb35800efe65 

Content-Transfer-Encoding: 7bit 

Content-Type: text/plain; charset="ISO-8859-1" 


Versao em texto 

--=_b3c5407ccf494306d78fbb35800efe65 

Content-Transfer-Encoding: quoted-printable 

Content-Type: text/html; charset="ISO-8859-1" 


Versao de email em HTML--=_b3c5407ccf494306d78fbb35800efe65-- 

. 

DEBUG: Recv: 250 OK id=1MYSd4-0005Ky-Jw 

DEBUG: Send: QUIT 

Respuesta

0

que la extensión de OpenSSL habilitada y las lenguas de directorio con "sa"? primero verifica los datos.

+0

En el phpinfo() Tengo: ... Compatibilidad con OpenSSL OpenSSL Versión \t OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 Lo que me vuelve loco es que con PEAR funciona. – Evandro

16

Trate de añadir esto:

$mail->SMTPAuth = true; 
$mail->SMTPSecure = "tls"; 

Al mirar a sus registros de depuración, se puede observar que el registro de PHPMailer no muestra esto:

(..snip..) 
SMTP -> ERROR: AUTH not accepted from server: 250 orion.bommtempo.net.br Hello admin-teste.bommtempo.com.br [200.155.129.6] 
(..snip..) 
503 AUTH command used when not advertised 
(..snip..) 

Mientras que el registro de PERA exitosa muestra esto:

DEBUG: Send: STARTTLS 
DEBUG: Recv: 220 TLS go ahead 

Supongo que pedir explícitamente a PHPMailer que use TLS lo pondrá en el camino correcto k.
Además, asegúrese de estar utilizando la versión más reciente de PHPMailer.

+1

esta respuesta resolvió mi problema. Mi empresa de hosting me dijo que no debía poner SSL, pero supongo que se requería TLS y se olvidaron de decirme: p – Sebas

0

Exim 4 requiere que el comando AUTH solo se envíe después de que el cliente emitió EHLO; los intentos de autenticación sin EHLO serían rechazados. Algunos servidores de correo requieren que EHLO se emita dos veces. PHPMailer aparentemente no lo hace. Si PHPMailer no le permite forzar el inicio de EHLO, debería cambiar al SwiftMailer 4.

+0

Solo para que quede registrado, PHPMailer hace lo correcto automáticamente y reenvía EHLO después de STARTTLS. – Synchro

38

extraño problema que he resuelto por el comentario esta línea

//$mail->IsSmtp(); 

la pizca de la versión última phpmailer (5,2)

+1

al comentar que la línea genera el resultado como si el correo electrónico se hubiera enviado, pero en realidad no se envía ese correo electrónico. –

+0

no es para mí ... sé que es extraño, pero este código está en mi entorno de producción y todos los correos electrónicos se envían ... (pero mi phpmailer tiene 1 año) – maurox

+1

Esto ocurre cuando se comenta esa línea: No se pudo crear instancia función de correo. Error de la aplicación de correo: no se pudo crear una instancia de la función de correo. – a77icu5

0

Comprobar si ha configurado restringir el saliente SMTP sólo a algunos usuarios del sistema (raíz, MTA, cartero...). Esa restricción puede prevenir a los spammers, pero redirigirá las conexiones SMTP salientes al servidor de correo local.

2

Esto me pasó a mí también. Para mí, Postfix estaba ubicado en el mismo servidor que el script PHP, y el error estaba sucediendo cuando usaba autenticación SMTP y smtp.domain.com en lugar de localhost.

Así que cuando me comentaron estas líneas:

$ mail-> SMTPAUTH = true;
$ mail-> SMTPSecure = "tls";

y establecer la sede de

$mail->Host = "localhost"; 

lugar

$ mail-> Host = 'smtp.mydomainiuse.com'

y funcionó :)

Cuestiones relacionadas