I have implemented the sending of emails through PHPMailer, and when I send the emails while the project is on the local host of my local server there is no problem to send them, but now that I have the project on the web server the sending of emails no longer works, I hope someone Can you help me understand what I have done wrong or that it is necessary to change once the project is implemented.
After some research, I think that the problem can be on the server configuration that i'm using, which is a LAMP Bitnami Application on Amazon Web Services Lightsail Instance.
And this is the code I am using for sending the emails:
<?php
error_reporting(0);
// INFORMATION
if(isset($_POST['valor'])) {
$valor = $_POST['valor'];
}
$tiempo = time();
$codigo = $valor + $tiempo;
$reservas = ControladorReservas::ctrMostrarReservas($valor);
foreach ($reservas as $reserva) {
$id = $reserva['id'];
$correo = $reserva['correo'];
$nombre = $reserva['nombre_reserva'];
$establecimiento = $reserva['establecimiento'];
$fecha = $reserva['fecha_reserva'];
$hora = $reserva['hora_reserva'];
}
// END OF RECEIVING INFORMATION
$titulo = 'Su reserva en / Your booking at '. $establecimiento .' ha sido confirmada / has been confirmed';
$cuerpo = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Demystifying Email Design</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body style="margin: 0; padding: 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="padding: 10px 0 30px 0;">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="border: 1px solid #cccccc; border-collapse: collapse;">
<tr>
<td bgcolor="#ffffff" style="padding: 40px 30px 40px 30px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="color: #153643; font-family: Arial, sans-serif; font-size: 24px;">
<b>Estimado / Dear ' . $nombre . ',</b>
</td>
</tr>
<tr>
<td style="padding: 20px 0 30px 0; color: #153643; font-family: Arial, sans-serif; font-size: 16px; line-height: 20px;">
<p> Su reservacion para '. $establecimiento .' el dia '. $fecha .' a las '. $hora .' horas HA SIDO CONFIRMADA EXITOSAMENTE </p>
<p> Your booking for '. $establecimiento .' the day '. $fecha .' at '. $hora .' hours HAS BEEN CONFIRMED SUCCESSFULLY </p>
<h3> Su codigo de reserva es / Your booking code is: ' . $codigo . '</h3>
<p> Recuerde proporcionar su codigo de reserva para hacer valido su regalo </p>
<p> Remeber to proporcionate your booking code to make your gift valid </p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#4ECDC4" style="padding: 30px 30px 30px 30px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="color: #ffffff; font-family: Arial, sans-serif; font-size: 14px;" width="75%">
® Rede, 2019<br/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
';
require_once('PHPMailer/PhpMailerAutoload.php');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->isHTML();
$mail->Username = 'correo@correo.com';
$mail->Password = "pass01";
$mail->SetFrom('prueba@quis.org');
//Estas 3 siguientes son personalizadas
$mail->Subject = $titulo; //email subject
$mail->Body = $cuerpo; //email body
$mail->AddAddress($correo); //receiver
$mail->Send();
?>
Already tried to change:
$mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl';
to false, because in other article I read that can be a problem if your domain doesn't have a ssl certificate, which is my case.
Really hope can help me to solve this problem, or to know what I'm doing wrong.
Thanks!