Foros del Web » Programando para Internet » PHP »

phpmailer

Estas en el tema de phpmailer en el foro de PHP en Foros del Web. hola estoy intentando incorporar phpmailer para el envio de mails desde mi web a traves de gmail El codigo que estoy usando es este: @import ...
  #1 (permalink)  
Antiguo 25/09/2009, 18:32
 
Fecha de Ingreso: julio-2009
Mensajes: 311
Antigüedad: 14 años, 9 meses
Puntos: 0
phpmailer

hola estoy intentando incorporar phpmailer para el envio de mails desde mi web
a traves de gmail
El codigo que estoy usando es este:

Código PHP:
Ver original
  1. <?
  2.   // primero hay que incluir la clase phpmailer para poder instanciar
  3.   //un objeto de la misma
  4.   require "includes/class.phpmailer.php";
  5.  
  6.   //instanciamos un objeto de la clase phpmailer al que llamamos
  7.   //por ejemplo mail
  8.   $mail = new phpmailer();
  9.   $mail->IsSMTP();
  10.  
  11.   //Definimos las propiedades y llamamos a los métodos correspondientes del objeto mail
  12.  
  13.   //Con PluginDir le indicamos a la clase phpmailer donde se
  14.   //encuentra la clase smtp que como he comentado al principio de
  15.   //este ejemplo va a estar en el subdirectorio includes
  16.  
  17.   $mail->PluginDir = "includes/";
  18.  
  19.   //Con la propiedad Mailer le indicamos que vamos a usar un
  20.   //servidor smtp
  21.  // $mail->Mailer = "smtp";
  22.  
  23.   //Asignamos a Host el nombre de nuestro servidor smtp
  24.   $mail->Host = "smtp.gmail.com";
  25.   $mail->Port = 465;
  26.   //Le indicamos que el servidor smtp requiere autenticación
  27.   $mail->SMTPAuth = true;
  28.   $mail->SMTPSecure = "ssl";
  29.   //Le decimos cual es nuestro nombre de usuario y password
  30.   $mail->Username = "[email protected]";
  31.   $mail->Password = "XXXXX";
  32.  
  33.   //Indicamos cual es nuestra dirección de correo y el nombre que
  34.   //queremos que vea el usuario que lee nuestro correo
  35.   $mail->From = "[email protected]";
  36.   $mail->FromName = "XXX";
  37.  
  38.   //el valor por defecto 10 de Timeout es un poco escaso dado que voy a usar
  39.   //una cuenta gratuita, por tanto lo pongo a 30
  40.   $mail->Timeout=30;
  41.  
  42.   //Indicamos cual es la dirección de destino del correo
  43.   $mail->AddAddress("[email protected]");
  44.  
  45.   //Asignamos asunto y cuerpo del mensaje
  46.   //El cuerpo del mensaje lo ponemos en formato html, haciendo
  47.   //que se vea en negrita
  48.   $mail->Subject = "Prueba de phpmailer";
  49.   $mail->Body = "<b>Mensaje de prueba mandado con phpmailer en formato html</b>";
  50.  
  51.   //Definimos AltBody por si el destinatario del correo no admite email con formato html
  52.   $mail->AltBody = "Mensaje de prueba mandado con phpmailer en formato solo texto";
  53.  
  54.   //se envia el mensaje, si no ha habido problemas
  55.   //la variable $exito tendra el valor true
  56.   $mail->IsHTML(true);
  57.   $exito = $mail->Send();
  58.  
  59.   //Si el mensaje no ha podido ser enviado se realizaran 4 intentos mas como mucho
  60.   //para intentar enviar el mensaje, cada intento se hara 5 segundos despues
  61.   //del anterior, para ello se usa la funcion sleep
  62.   $intentos=1;
  63.   while ((!$exito) && ($intentos < 5)) {
  64.     sleep(5);
  65.         //echo $mail->ErrorInfo;
  66.         $exito = $mail->Send();
  67.         $intentos=$intentos+1;
  68.  
  69.    }
  70.  
  71.  
  72.    if(!$exito)
  73.    {
  74.     echo "Problemas enviando correo electrónico a ".$valor;
  75.     echo "<br/>".$mail->ErrorInfo;
  76.    }
  77.    else
  78.    {
  79.     echo "Mensaje enviado correctamente";
  80.    }
  81. ?>

en la carpeta includes tengo las ultimas versiones de class.phpmailer.php y class.smtp.php
y al intentar ponen en marcha me sale el siguiente :

Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /home/a3434157/public_html/includes/class.smtp.php on line 122

adjunto el codigo de class.smtp

Código PHP:
Ver original
  1. <?php
  2. /*~ class.smtp.php
  3. .---------------------------------------------------------------------------.
  4. |  Software: PHPMailer - PHP email class                                    |
  5. |   Version: 2.1                                                            |
  6. |   Contact: via sourceforge.net support pages (also [url]www.codeworxtech.com[/url])  |
  7. |      Info: [url]http://phpmailer.sourceforge.net[/url]                               |
  8. |   Support: [url]http://sourceforge.net/projects/phpmailer/[/url]                     |
  9. | ------------------------------------------------------------------------- |
  10. |    Author: Andy Prevost (project admininistrator)                         |
  11. |    Author: Brent R. Matzelle (original founder)                           |
  12. | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved.               |
  13. | Copyright (c) 2001-2003, Brent R. Matzelle                                |
  14. | ------------------------------------------------------------------------- |
  15. |   License: Distributed under the Lesser General Public License (LGPL)     |
  16. |            [url]http://www.gnu.org/copyleft/lesser.html[/url]                        |
  17. | This program is distributed in the hope that it will be useful - WITHOUT  |
  18. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
  19. | FITNESS FOR A PARTICULAR PURPOSE.                                         |
  20. | ------------------------------------------------------------------------- |
  21. | We offer a number of paid services ([url]www.codeworxtech.com):[/url]                |
  22. | - Web Hosting on highly optimized fast and secure servers                 |
  23. | - Technology Consulting                                                   |
  24. | - Oursourcing (highly qualified programmers and graphic designers)        |
  25. '---------------------------------------------------------------------------'
  26.  
  27. /**
  28.  * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
  29.  * commands except TURN which will always return a not implemented
  30.  * error. SMTP also provides some utility methods for sending mail
  31.  * to an SMTP server.
  32.  * @package PHPMailer
  33.  * @author Chris Ryan
  34.  */
  35.  
  36. class SMTP {
  37.   /**
  38.    *  SMTP server port
  39.    *  @var int
  40.    */
  41.   public $SMTP_PORT = 25;
  42.  
  43.   /**
  44.    *  SMTP reply line ending
  45.    *  @var string
  46.    */
  47.   public $CRLF = "\r\n";
  48.  
  49.   /**
  50.    *  Sets whether debugging is turned on
  51.    *  @var bool
  52.    */
  53.   public $do_debug;       // the level of debug to perform
  54.  
  55.   /**
  56.    *  Sets VERP use on/off (default is off)
  57.    *  @var bool
  58.    */
  59.   public $do_verp = false;
  60.  
  61.   /**#@+
  62.    * @access private
  63.    */
  64.   private $smtp_conn;      // the socket to the server
  65.   private $error;          // error if any on the last call
  66.   private $helo_rply;      // the reply the server sent to us for HELO
  67.   /**#@-*/
  68.  
  69.   /**
  70.    * Initialize the class so that the data is in a known state.
  71.    * @access public
  72.    * @return void
  73.    */
  74.   public function __construct() {
  75.     $this->smtp_conn = 0;
  76.     $this->error = null;
  77.     $this->helo_rply = null;
  78.  
  79.     $this->do_debug = 0;
  80.   }
  81.  
  82.   /*************************************************************
  83.    *                    CONNECTION FUNCTIONS                  *
  84.    ***********************************************************/
  85.  
  86.   /**
  87.    * Connect to the server specified on the port specified.
  88.    * If the port is not specified use the default SMTP_PORT.
  89.    * If tval is specified then a connection will try and be
  90.    * established with the server for that number of seconds.
  91.    * If tval is not specified the default is 30 seconds to
  92.    * try on the connection.
  93.    *
  94.    * SMTP CODE SUCCESS: 220
  95.    * SMTP CODE FAILURE: 421
  96.    * @access public
  97.    * @return bool
  98.    */
  99.   public function Connect($host,$port=0,$tval=30) {
  100.     /* set the error val to null so there is no confusion */
  101.     $this->error = null;
  102.  
  103.     /* make sure we are __not__ connected */
  104.     if($this->connected()) {
  105.       /* ok we are connected! what should we do?
  106.        * for now we will just give an error saying we
  107.        * are already connected
  108.        */
  109.       $this->error = array("error" => "Already connected to a server");
  110.       return false;
  111.     }
  112.  
  113.     if(empty($port)) {
  114.       $port = $this->SMTP_PORT;
  115.     }
  116.  
  117.     /* connect to the smtp server */
  118.     $this->smtp_conn = fsockopen($host,    // the host of the server
  119.                                  $port,    // the port to use
  120.                                  $errno,   // error number if any
  121.                                  $errstr,  // error message if any
  122.                                  $tval);   // give up after ? secs         <<<<<linea 122
  123.     /* verify we connected properly */
  124.     if(empty($this->smtp_conn)) {
  125.       $this->error = array("error" => "Failed to connect to server",
  126.                            "errno" => $errno,
  127.                            "errstr" => $errstr);
  128.       if($this->do_debug >= 1) {
  129.         echo "SMTP -> ERROR: " . $this->error["error"] .
  130.                  ": $errstr ($errno)" . $this->CRLF;
  131.       }
  132.       return false;
  133.     }

Si me pueden ayudar se los voy a agradecer mucho pues mis conociemientos son muy limitados y si ves algun error en la configuaracion hacemelo saber
Gracias por adelantado o si tenes algun script que quieras compartir para ayudarme tambien me seria util

Última edición por GatorV; 26/09/2009 a las 16:59
  #2 (permalink)  
Antiguo 26/09/2009, 17:02
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: phpmailer

El problema es que tu instalación de PHP no tiene soporte para SSL, necesitas recompilarlo y agregar las extensiones para conectarte a un servidor seguro SSL.

Saludos.
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 14:32.