Luego de mucho trabajar pudimos dar con la solución de este dilema que tantos usuarios de esta web tienen. Si tienes algún detalle que compartir no dejes de compartir tu información.
Solución:
Aquí hay un ejemplo de trabajo:
IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 2; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "tls"; //Secure conection
$Mail->Port = 587; // set the SMTP port
$Mail->Username = '[email protected]'; // SMTP account username
$Mail->Password = 'MyGmailPassword'; // SMTP account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8rn';
$Mail->From = '[email protected]';
$Mail->FromName = 'GMail Test';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress( $ToEmail ); // To:
$Mail->isHTML( TRUE );
$Mail->Body = $MessageHTML;
$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
if ( $Mail->IsError() ) // ADDED - This error checking was missing
return FALSE;
else
return TRUE;
$ToEmail = '[email protected]';
$ToName = 'Name';
$Send = SendMail( $ToEmail, $MessageHTML, $MessageTEXT );
if ( $Send )
echo " Sent OK
";
else
echo " ERROR
";
die;
?>
Probé este script y no tuve problemas para enviar varios mensajes.
ACTUALIZADO:
Esta es la respuesta típica de Gmail en caso de éxito:
SMTP -> FROM SERVER:220 mx.google.com ESMTP 20sm6345523qek.6
SMTP -> FROM SERVER: 250-mx.google.com at your service, [181.155.13.39]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS
SMTP -> FROM SERVER: 250-mx.google.com at your service, [181.155.13.39]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2
250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:250 2.1.0 OK 20sm6345523qek.6
SMTP -> FROM SERVER:250 2.1.5 OK 20sm6345523qek.6
SMTP -> FROM SERVER:354 Go ahead 20sm6345523qek.6
SMTP -> FROM SERVER:250 2.0.0 OK 1353474062 20sm6345523qek.6
SMTP -> FROM SERVER:221 2.0.0 closing connection 20sm6345523qek.6
Su código no funciona porque no configuró el SMTPSecure
opción a ssl
que se requiere para gmail
cuenta
include_once "/lib/phpmailer/PHPMailer.class.php";
include_once "/lib/phpmailer/SMTP.class.php";
include_once "/lib/phpmailer/POP3.class.php";
$mail = new PHPMailer(true);
$mail->IsSMTP();
try
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'ssl'; //<----------------- You missed this
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; //
$mail->Username = "[email protected]";
$mail->Password = "xxxxxx";
$mail->AddAddress('[email protected]', 'John Doe');
$mail->SetFrom('[email protected]', 'First Last');
$mail->Subject = 'This is a TEST message';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$body = "To view the message, please use an HTML compatible email viewer!"; // automatically
$mail->MsgHTML($body);
$mail->Send();
echo "Message Sent OKn";
catch ( phpmailerException $e )
echo $e->errorMessage();
catch ( Exception $e )
echo $e->getMessage();
Producción
SMTP -> FROM SERVER:220 mx.google.com ESMTP q22sm2927759bkv.16
SMTP -> FROM SERVER: 250-mx.google.com at your service, [62.173.54.190] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:250 2.1.0 OK q22sm2927759bkv.16
SMTP -> FROM SERVER:250 2.1.5 OK q22sm2927759bkv.16
SMTP -> FROM SERVER:354 Go ahead q22sm2927759bkv.16
SMTP -> FROM SERVER:250 2.0.0 OK 1353341553 q22sm2927759bkv.16
Message Sent OK
Si te gusta la informática, tienes el poder dejar un ensayo acerca de qué le añadirías a este escrito.
¡Haz clic para puntuar esta entrada!
(Votos: 2 Promedio: 4.5)