Error sending mail with phpmailer

0

I am trying to send an email with the phpmailer library, in local it works correctly, but when I have uploaded it to a hosting it returns the following error: Could not instantiate mail function.

The configuration I have is the following:

$nombre = $_POST['nombre'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];

require_once('lib/phpmailer/class.phpmailer.php');
$mail = new PHPMailer();

//indico a la clase que use SMTP
$mail->isSMTP();

$mail->CharSet = "UTF-8";

//permite modo debug para ver mensajes de las cosas que van ocurriendo
$mail->SMTPDebug = 2;

//Debo de hacer autenticación SMTP
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';

//indico el servidor de Gmail para SMTP
$mail->Host = "smtp.gmail.com";

//indico el puerto que usa Gmail
$mail->Port = 465;

//indico un usuario / clave de un usuario de gmail
$mail->Username = "[email protected]";
$mail->Password = "pass";
$mail->setFrom('[email protected]', 'Restaurante ');
$mail->addReplyTo($email, $nombre);
$mail->Subject = "Nuevo mensaje recibido .";
$mail->msgHTML($mensaje);

//indico destinatario
//$address = "[email protected]";
$address = "[email protected]";
$mail->addAddress($address, "Restaurante");

if(!$mail->send()) {
    echo "Error al enviar: ". $mail->ErrorInfo;
} else {
    echo "Mensaje enviado!";
}

Do you know what may be happening?

Thank you very much. Greetings.

    
asked by Enrique Rodrigo 08.04.2017 в 09:27
source

2 answers

0

is already solved. The problem was that I had to generate an application password. Apparently now gmail wants to use its own password to use the account from an app.

Greetings.

    
answered by 10.04.2017 / 19:42
source
0

I have modified some things and now this error is thrown at me:

2017-04-09 08:33:17 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    
answered by 09.04.2017 в 10:41