Foros del Web » Programando para Internet » PHP »

smtp.php

Estas en el tema de smtp.php en el foro de PHP en Foros del Web. Hola: Estoy instalando un gestor de Incidencias llamado Cerberus Helpdesk,el problema esta en que configuro el servidor smtp y me falla el envio en el ...
  #1 (permalink)  
Antiguo 20/03/2009, 02:35
 
Fecha de Ingreso: junio-2008
Mensajes: 160
Antigüedad: 15 años, 10 meses
Puntos: 2
smtp.php

Hola:

Estoy instalando un gestor de Incidencias llamado Cerberus Helpdesk,el problema esta en que configuro el servidor smtp y me falla el envio en el smtp.php:

El error que me da es...:

Could not send e-mail to requester list. (EHLO command failed, output: ; Not connected!)

Os pongo mi código del smtp.php
Apuntar que utilizo php5,que viene con lampp.
Mi puerto del smtp es 587 y no tiene ningun tipo de seguridad(TLS,ssl.....)
El Servidor de correo lo tengo en hosting..

Debe de petar en la linea 208 yo creo ....tampoco me lo pone...os la pongo en negrita....
  #2 (permalink)  
Antiguo 20/03/2009, 02:35
 
Fecha de Ingreso: junio-2008
Mensajes: 160
Antigüedad: 15 años, 10 meses
Puntos: 2
Respuesta: smtp.php

<?php

define('SMTP_STATUS_NOT_CONNECTED', 1, TRUE);

define('SMTP_STATUS_CONNECTED', 2, TRUE);

class smtp{

var $authenticated;

var $connection;

var $recipients;

var $headers;

var $timeout;

var $errors;

var $status;

var $body;

var $from;

var $host;

var $port;

var $helo;

var $auth;

var $user;

var $pass;




function smtp($params = array()){

$cfg = CerConfiguration::getInstance();



if(!defined('CRLF'))

define('CRLF', "\r\n", TRUE);



$this->authenticated = FALSE;

$this->timeout = 5;

$this->status = SMTP_STATUS_NOT_CONNECTED;

$this->host = $cfg->settings["smtp_server"]; // 'localhost'

$this->port = 587;

$this->helo = 'localhost';

$this->auth = FALSE;

$this->user = '';

$this->pass = '';

$this->errors = array();



foreach($params as $key => $value){

$this->$key = $value;

}

}


function &connect($params = array()){



if(!isset($this->status)){

$obj = new smtp($params);

if($obj->connect()){

$obj->status = SMTP_STATUS_CONNECTED;

}



return $obj;



}else{

$this->connection = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);

if(function_exists('socket_set_timeout')){

@socket_set_timeout($this->connection, 5, 0);

}



$greeting = $this->get_data();

if(is_resource($this->connection)){

return $this->auth ? $this->ehlo() : $this->helo();

}else{

$this->errors[] = 'Failed to connect to server: '.$errstr;

return FALSE;

}

}

}


function send($params = array()){



foreach($params as $key => $value){

$this->set($key, $value);

}



if($this->is_connected()){



// Do we auth or not? Note the distinction between the auth variable and auth() function

if($this->auth AND !$this->authenticated){

if(!$this->auth())

return FALSE;

}



$this->mail($this->from);

if(is_array($this->recipients))

foreach($this->recipients as $value)

$this->rcpt($value);

else

$this->rcpt($this->recipients);



if(!$this->data())

return FALSE;



// Transparency

$headers = str_replace(CRLF.'.', CRLF.'..', trim(implode(CRLF, $this->headers)));

$body = str_replace(CRLF.'.', CRLF.'..', $this->body);

$body = $body[0] == '.' ? '.'.$body : $body;



$this->send_data($headers);

$this->send_data('');

$this->send_data($body);

$this->send_data('.');



$result = (substr(trim($this->get_data()), 0, 3) === '250');

//$this->rset();

return $result;

}else{

$this->errors[] = 'Not connected!';

return FALSE;

}

}



/**

* Function to implement HELO cmd

*/



function helo(){

if(is_resource($this->connection)

AND $this->send_data('HELO '.$this->helo)

AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){



return TRUE;



}else{

$this->errors[] = 'HELO command failed, output: ' . trim(substr(trim($error),3));

return FALSE;

}

}



/**

* Function to implement EHLO cmd

*/



function ehlo(){

if(is_resource($this->connection)

AND $this->send_data('EHLO '.$this->helo)

AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){



return TRUE;



}else{

$this->errors[] = 'EHLO command failed, output: ' . trim(substr(trim($error),3));

return FALSE;

}

}



/**

* Function to implement RSET cmd

*/



function rset(){

if(is_resource($this->connection)

AND $this->send_data('RSET')

AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){



return TRUE;



}else{

$this->errors[] = 'RSET command failed, output: ' . trim(substr(trim($error),3));

return FALSE;

}

}



/**

* Function to implement QUIT cmd

*/



function quit(){

if(is_resource($this->connection)

AND $this->send_data('QUIT')

AND substr(trim($error = $this->get_data()), 0, 3) === '221' ){



fclose($this->connection);

$this->status = SMTP_STATUS_NOT_CONNECTED;

return TRUE;



}else{

$this->errors[] = 'QUIT command failed, output: ' . trim(substr(trim($error),3));

return FALSE;

}

}



/**

* Function to implement AUTH cmd

*/



function auth(){

if(is_resource($this->connection)

AND $this->send_data('AUTH LOGIN')

AND substr(trim($error = $this->get_data()), 0, 3) === '334'

AND $this->send_data(base64_encode($this->user)) // Send username

AND substr(trim($error = $this->get_data()),0,3) === '334'

AND $this->send_data(base64_encode($this->pass)) // Send password

AND substr(trim($error = $this->get_data()),0,3) === '235' ){



$this->authenticated = TRUE;

return TRUE;



}else{

$this->errors[] = 'AUTH command failed: ' . trim(substr(trim($error),3));

return FALSE;

}

}



/**

* Function that handles the MAIL FROM: cmd

*/



function mail($from){



if($this->is_connected()) {

$from = trim($from);

if(strstr($from, "<")) {

$from = strstr($from, "<");

$from = substr($from, 1, -1);

}

if($this->send_data('MAIL FROM:<'.$from.'>')

&& substr(trim($this->get_data()), 0, 2) === '25') {

return TRUE;

}

}

else

return FALSE;

}



/**

* Function that handles the RCPT TO: cmd

*/



function rcpt($to){



if($this->is_connected()) {

$to = trim($to);

if(strstr($to, "<")) {

$to = strstr($to, "<");

$to = substr($to, 1, -1);

}

if($this->send_data('RCPT TO:<'.$to.'>')

&& substr(trim($error = $this->get_data()), 0, 2) === '25' ) {

return TRUE;

}

}

else {

$this->errors[] = trim(substr(trim($error), 3));

return FALSE;

}

}



/**

* Function that sends the DATA cmd

*/



function data(){



if($this->is_connected()

AND $this->send_data('DATA')

AND substr(trim($error = $this->get_data()), 0, 3) === '354' ){



return TRUE;



}else{

$this->errors[] = trim(substr(trim($error), 3));

return FALSE;

}

}



/**

* Function to determine if this object

* is connected to the server or not.

*/



function is_connected(){



return (is_resource($this->connection) AND ($this->status === SMTP_STATUS_CONNECTED));

}



/**

* Function to send a bit of data

*/



function send_data($data){



if(is_resource($this->connection)){

return fwrite($this->connection, $data.CRLF, strlen($data)+2);



}else

return FALSE;

}



/**

* Function to get data.

*/



function &get_data(){



$return = '';

$line = '';

$loops = 0;



if(is_resource($this->connection)){

while((strpos($return, CRLF) === FALSE OR substr($line,3,1) !== ' ') AND $loops < 100){

$line = fgets($this->connection, 512);

$return .= $line;

$loops++;

}

return $return;



}else

return FALSE;

}



/**

* Sets a variable

*/



function set($var, $value){



$this->$var = $value;

return TRUE;

}



} // End of class

?>

Última edición por Gero_xh; 20/03/2009 a las 10:14
  #3 (permalink)  
Antiguo 20/03/2009, 12:36
 
Fecha de Ingreso: abril-2006
Mensajes: 1.128
Antigüedad: 18 años
Puntos: 33
Respuesta: smtp.php

Gero_xh:

Cita:
$this->helo = 'localhost';
Creo esta configuracion de tu codigo esta mala y creo
deberia ser 'EHLO' o algo parecido.

Hay algo que no te entiendo bien, estas tratando de mandar correo
utilizando sockets pero hablas de un servidor de correo tuyo.

Este codigo es para enviar directo a un servidor de correo externo,
pero debes configurarlo adecuadamente.

Saludos
Franco
  #4 (permalink)  
Antiguo 21/03/2009, 13:23
 
Fecha de Ingreso: junio-2008
Mensajes: 160
Antigüedad: 15 años, 10 meses
Puntos: 2
Respuesta: smtp.php

Gracias por responder .....estoy atascado ahi todavía me da el error:

Could not send e-mail to requester list. (EHLO command failed, output: ; Not connected!)

La verdad que no tengo mucha idea de programación de php y sobre sockect soy de sistemas!!

Lo que estoy haciendo es instalar una aplicación la cual tiene un apartado para poder enviar correos ,para ello hay que configurarle vía web el servidor smtp.

Este servidor es el servidor de correo, el cual envia mensajes ....

Esto esta hecho bien porque pongo la configuración igual que en mi cliente de correo ,donde funciona.

Pero por lo que sea el fichero php "smtp.php" que es el encargado de llevar a cabo la conexión con el servidor cogiendo los datos de la web para que este envie el correo falla dandome el error ese......
Could not send e-mail to requester list. (EHLO command failed, output: ; Not connected!)

Lo unico que he cambiado en el fichero smtp.php a mano es el puerto que por defecto es siempre el 25 y el de mi smtp es el 587.

No creo que sea problema de que la configuración este mal ,xq sino daría un mensaje más concreto como:

-No se ha podido conectar con smtp
ó
-La contraseña de usuario esta mal .....etc

El error creo que esta en el código php,es una aplicación prefabricada ,asi que este codigo venia por defecto....
No se que cambiar .....probare a cambiar

$this->helo = 'localhost'; ------>$this->ehlo = 'localhost';

  #5 (permalink)  
Antiguo 23/03/2009, 05:51
 
Fecha de Ingreso: junio-2008
Mensajes: 160
Antigüedad: 15 años, 10 meses
Puntos: 2
Respuesta: smtp.php

.....probare a cambiar

$this->helo = 'localhost'; ------>$this->ehlo = 'localhost';


Esto no ha funcionado.....

  #6 (permalink)  
Antiguo 23/03/2009, 06:24
Avatar de rafaconpu  
Fecha de Ingreso: febrero-2006
Mensajes: 331
Antigüedad: 18 años, 1 mes
Puntos: 3
Respuesta: smtp.php

Hola.

Si lo que pretendes es enviar correo desde una dirección de email (remitente) utilizando el servidor SMTP (con su servidor saliente mail.smtp.com por poner un ejemplo), ¿porqué no haces uso de la clase phpmailer y smtp.phpmailer.php?

Esas clases ya están hechas, bastante completitas y te permiten enviar correo sin problemas.

Únicamente debes tener en cuenta una serie de requisitos a configurarle:

- Servidor
- Servidor de correo saliente SMTP
- Habilitar el envío de SMTP para la clase phpmailer
- Email remitente

Creo no dejarme nada atrás.

Si estás interesado ya te digo con más detalle qué deberías configurar y cómo.

Un saludo.
  #7 (permalink)  
Antiguo 23/03/2009, 08:59
 
Fecha de Ingreso: junio-2008
Mensajes: 160
Antigüedad: 15 años, 10 meses
Puntos: 2
Respuesta: smtp.php

Hola:

Bueno ya se porque fallaba ,la respuesta es :

http://www.spamhaus.org

En esta Url hay una base de datos de Ips externas las cuales son consideradas como spam,por lo que sea mi IP externa pues la han metido una de esas listas.....

Cuando se establece la conexión con el servidor de correo smtp ( de esta conexión se encarga el EHLO ),el servidor de correo comprueba las listas de spamde esa url para protegerse,....esta comprobación supongo que lo puedes configurar tú en tu servidor de correo ,yo tengo el correo en un hosting.............

Si entras en la URL ( http://www.spamhaus.org ) pones tu IP externa con la que sales hacia fuera , te dira si estas dentro de alguna lista y desde ahí también puedes borrarte de la lista.,tarda 30 min en borrarte de la lista/as.

Mi ip externa aparecia en una de las listas ,me he borrado ...y ahora funciona correctamente.......

Por si os sirve......

Gracias de todas formas rafa conpu...

Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:31.