SMTP error: Could not connect to the SMTP server

0

I can not send emails from my application, this is with the phpMailer library, when sending emails it shows me the error message SMTP: Could not connect to the SMTP server.

Enter all the parameters of the server, which is smtp.gmail.com, user, password, but it does not allow me to send emails.


                                   para verificar la configuracion SMTP


Test generado por : '.$_SESSION["NOMBREFUNCIONARIO"]; $mail = new PHPMailer(true); $mail->IsSMTP(); $mail->SMTPDebug = $Debug; $mail->SetLanguage('es'); $mail->MsgHTML($body); $mail->SMTPAuth = $SMTPAuth; $mail->Port = $Port; switch ($SMTPSecure) { case 'SSL': { $mail->SMTPSecure = 'ssl'; } case 'TLS': { $mail->SMTPSecure = 'tls'; } } $mail->Host = $Host; $mail->Username = $Username; $mail->Password = $Password; $mail->From = $From; $mail->FromName = $FromName; $mail->ConfirmReadingTo = $correo_personal; $mail->Subject = $Subject; $mail->AltBody = 'Para poder ver este mensaje utilize un cliente de correo compatible con contenido HTML!'; $mail->AddAddress('[email protected]'); $mail->AddAddress($CORRALO); if(!$mail->Send()) { $ale = '


Error enviando e-mail
'.$mail->ErrorInfo.'

'; echo $ale; } else { $ale = '


e-mail enviado Correctamente!

Esta Configuracion es valida.

'; echo $ale; } }catch (phpmailerException $e) { echo $e->errorMessage(); }catch (Exception $e) { echo $e->getMessage(); } }else{ ?> Por favor escriba una direccion de correo valida para realizar la prueba de envio de e-mail

asiste@server$\ document.getElementById('CORRALO_SMTP').focus(); function validar(e) { tecla = (document.all) ? e.keyCode : e.which; if (tecla==13) enviar(); } function enviar(){ var VARGET = 'CORREO='; VARGET += '&SERVIDOR='; VARGET += '&USUARIO='; VARGET += '&PASSWORD='; VARGET += '&SEGURIDAD='; VARGET += '&PUERTO='; VARGET += '&AUTENTICACION='; VARGET += '&CORRALO='+document.getElementById('CORRALO_SMTP').value; FAjax('test_smtp.php','RECIBE_TEST_SMTP',VARGET,'post','loading3'); document.getElementById('CORRALO2').innerHTML = document.getElementById('CORRALO_SMTP').value; document.getElementById('CORRALO_SMTP').style.visibility = "hidden"; }
    
asked by Luis Eduardo Martinez Ocoro 27.09.2017 в 23:46
source

2 answers

1

Hello, I recommend you to be more specific with the type of error that you get when trying to send the mail.

Well, here is an example of how to send emails using PHPMailer and smtp gmail.com

<?php

require_once('PHPMailer/PHPMailerAutoload.php'); 

$mail = new PHPMailer(true); 
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
$mail->SMTPDebug = 2; 
$mail->IsSMTP();
$mail->SMTPAuth = true;
//$mail->SMTPSecure = "ssl";
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;// TCP port to connect to
$mail->CharSet = 'UTF-8';
$mail->Username ='[email protected]'; //Email para enviar
$mail->Password = '2132'; //Su password
//Agregar destinatario
$mail->setFrom('[email protected]', 'Botxtrem Solutions');
$mail->AddAddress('[email protected]');//A quien mandar email
$mail->SMTPKeepAlive = true;  
$mail->Mailer = "smtp"; 


    //Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'PRUEBA 6';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
  echo 'Error al enviar email';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Mail enviado correctamente';
}

Saludes

    
answered by 16.03.2018 в 06:49
0

From what I see in the code, nowhere do you call the autoload and you still have to call use PHPMailer \ PHPMailer \ PHPMailer; use PHPMailer \ PHPMailer \ Exception;

    
answered by 17.01.2019 в 16:50