Hi, I'm trying to work with the PHPMailer
library, which works correctly if I do not enter the SMTP
method, if I add the SMTP
method that my server allows to configure, it sends me this error message:
Fatal error: Uncaught Error: Class 'SMTP' not found in /homepages htdocs/prueba/app/php/class.phpmailer.php:1347 Stack trace: #0 /homepages/htdocs/prueba/app/php/class.phpmailer.php(1426): PHPMailer->getSMTPInstance() #1 /homepages/htdocs/prueba/app/php/class.phpmailer.php(1366): PHPMailer->smtpConnect(Array) #2 /homepages/htdocs/prueba/app/php/class.phpmailer.php(1209): PHPMailer->smtpSend('Date: Mon, 26 D...', '\n\t\t\t\t<head>\t\n\t\t...') #3 /homepages/htdocs/prueba/app/php/class.phpmailer.php(1098): PHPMailer->postSend() #4 /homepages/htdocs/prueba/app/php/configuracion/modif_password_user.php(168): PHPMailer->send() #5 {main} thrown in /homepages/htdocs/prueba/app/php/class.phpmailer.php on line 1347
Line 1347:
public function getSMTPInstance()
{
if (!is_object($this->smtp)) {
$this->smtp = new SMTP; //Linea 1347
}
return $this->smtp;
}
I've also tried with my account GMAIL
and it throws me the same bug.
My PHP code:
<?php
//Componemos mensaje de envio
//Obtenemos datos del usuario.
$nombre = ucfirst($_POST['nombre'] ?: '');
$apellidos = $_POST['apellidos'] ?: '';
$correo = $_POST['mail'] ?: '';
//Incluimos libreria PHPmailer.
require'./../class.phpmailer.php';
//Nuevo correo electronico.
$mail = new PHPMailer;
//Caracteres.
$mail->CharSet = 'UTF-8';
//Si añado este bloque de codigo me lanza error //////////////////////
//Habilitar la depuración
$mail->SMTPDebug = 3;
//Establecer PHPMailer para usar SMTP
$mail->isSMTP();
//Establecer nombre de host SMTP
$mail->Host = "smtp.1and1.es";
//Establecer como verdadero si el host SMTP requiere autenticación
$mail->SMTPAuth = true;
//nombre de usuario y contraseña servidor SMTP
$mail->Username = "mi_usuario";
$mail->Password = "mi_password";
//Si SMTP requiere encriptación TLS
$mail->SMTPSecure = "tls";
//Establecer el puerto TCP para conectarse a
$mail->Port = 587;
// /////////////////////////////////////////////////////////////////////
#Si elimino dicho bloque funciona correctamente el envio de correo.
//De dirección correo electrónico y el nombre
$mail->From = "info@tu_dominio.com";
$mail->FromName = "nombre_dominio";
//Dirección de envio y nombre.
$mail->addAddress($correo, $nombre . " " . $apellidos);
// Responder a
$mail->addReplyTo("info@tu_dominio.com","nombre_dominio");
//BCC -> incluir copia oculta de email enviado.
$mail->addBCC("info@tu_dominio.com");
//Enviar codigo HTML o texto plano.
$mail->isHTML(true);
//Titulo email.
$mail->Subject = "El dominio informa que tu contraseña de acceso fue modificada.";
//Cuerpo email con HTML.
$mail->Body =
"
<head>
<style>
body {
height: 100%; width: 100%; max-width: 100%;
font-family: 'Tahoma', arial;
background-color: #D8D8D8;
overflow: hidden;
}
.wit {
display: block; position:relative;
width: 100%; max-width:80%;
background-color: #FFF;
left:10%;
}
.blue { color: #178195; }
.bold { font-weight: bold; }
.grey { color: #585858; }
.padding32 { padding: 32px; }
</style>
</head>
<body>
<div class=wit>
<div class=padding32>
<img src='http://mi_dominio.com/img/logotipo-mini.png' style='min-width:100px' />
<h2 class='inline m-L'><b>Aprende a tu estilo de vida</b></h2>
<br />
<span class='bold'> $nombre</span>, tu contraseña fue modificada, en caso que no fuiste tú, ponga se en contacto con info@mi_dominio.com con una breve descripción a tu problema, mantenemos seguro la plataforma.<br />
<br />
Se modificó el $fecha_personal, con dirección de IP: $ip_adres<br />
<br />
<h4 class=bold>Atentamente:</h4>
<span class=grey>Equipo Mi_dominio </span><br />
Saludos.<br />
</div>
</div>
</body>
";
if(!$mail->send()) {
//error, no se envio el correo
} else {
//Se envio correctamente
}
?>
Note: Doing tests without using
SMTP
as you can see in the images below in some case does not apply the stylesCSS
, in this case Hotmail (Outlook) opening from desktop.
Does anyone know why the CSS
styles do not apply well, as I understand should I correctly apply the styles in Hotmail (Outlook)?
I made some own test, and in vede use PHPMailer
, use the function mail()
, and the same thing happens, does not always apply well styles CSS
Allowed style reference list:
Examples of received emails:
SMTP mail configuration