1

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%">
                                                &reg; 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!

JJS_Vegu
  • 55
  • 1
  • 4
  • 3
    If that's your actual password, you'll want to change it immediately. – Alex Howansky Sep 19 '19 at 16:58
  • 2
    exactly what problem are you seeing? You get an error? Or the emails just aren't delivered? Setting a "from" field different from the domain you're sending from is rarely a good idea - it's a good way to get your mail marked as spam. But that's jumping ahead, we don't even know if the Send() command is actually succeeding. Please provide a more detailed description of the problem. "no longer works" isn't an error anyone can fix. – ADyson Sep 19 '19 at 17:00
  • You're using an old version of PHPMailer and have based your code on an obsolete example, you have no error checking, no error or debug output, you've not read the docs, nor read the many identical questions on here. It's nothing to do with whether you have a certificate for your site or not; it's most likely that your ISP blocks outbound SMTP. – Synchro Sep 19 '19 at 18:16
  • @AlexHowansky It's a fake password for the post, but thanks! – JJS_Vegu Sep 19 '19 at 21:23
  • Hi @ADyson, thanks for your comment. Know I know if the Send() command is getting executed with a If Conditional, and writte a $mail->SMTPDebug = 1; to catch a error, but the server didn't give me any error... I'll keep trying to get the problem and write the actualizations. Any idea or help is welcome, thanks. – JJS_Vegu Sep 19 '19 at 21:54
  • I didn't ask if Send() was getting **executed**, I asked if it was **succeeding** when executed. The function will return true or false depending on the result of trying to send the mail. You aren't checking for that. A simple checking routine: `if(!$mail->send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; }` (courtesy of the [official tutorial](https://github.com/PHPMailer/PHPMailer/wiki/Tutorial)). You might also want to read this: https://stackoverflow.com/questions/2386544/error-handling-with-phpmailer – ADyson Sep 19 '19 at 22:01

0 Answers0