I try to create a contact form that will send your data to a gmail email. For this I use the library PHPMailer
, but first I am trying to get the mail with a simple text, that is without passing any variable. The problem is that it gives an error (apparently of syntax) as if it were not recognizing the parameters of class phpMailer
.
This is the error
Parse error: syntax error, unexpected '=' in C: \ wamp \ www \ CU \ sendbymail.php on line 11
This is the php code:
require_once("class.phpmailer.php");
require_once('class.smtp.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$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 = "usuarioX";
$mail->Password = "passwordX";
$mail->SetFrom('[email protected]', 'Nombre');
$mail->AddReplyTo("[email protected]","Nombre");
$mail->Subject = "Asunto del correo";
$mail->MsgHTML("Hola, este es el cuerpo del mensaje!");
//indico destinatario
$address = "[email protected]";
$mail->AddAddress($address, "Mi nombre");
if(!$mail->Send()) {
echo "Error al enviar: " . $mail->ErrorInfo;
}
else {
echo "Mensaje enviado!";
}
Then, line 11 of the code to which the error refers is this:
$mail->SMTPDebug = 2;
I read again and again and I do not see any error in that line or in any other of that file. However when I remove it or comment then the error gives me in the next where the next operator =
is, that is, in this:
$mail->SMTPAuth = true;
And so on with the other lines. However, I perform any simple operation using this operator ( =
) and that does not require the use of class PHPMailer
, and, in this case, it is recognized and the operation is executed. So I suspect that the error has to do something that is not loading well the class phpMailer
or can not access their methods, but can not see where the error is.