0

I have developed a small webapp. Before uploading it to hosting*r(hosting provider), I did the tests and everything worked normally. One of the functions of this webapp is that it sends notifications by mail using PHPMailer. But here I have a problem, the emails are sent from localhost, but once in the hosting the emails are no longer sent. I contacted support and they told me that dns records were missing, they gave me a solution, I waited for the dns propagation, but it still does not work.

  • Hosting*r has sendmail by default, I deactivated it.
  • I am not using composer.
  • I tried smtp and ssl and neither works.

Attached is the script I am using:

class Email extends PHPMailer{
<?php
/* librerias necesarias para que el proyecto pueda enviar emails */
require('class.phpmailer.php');
include("class.smtp.php");

---some lines ommited---
public function ticket_asignado($tick_id){
        $this->IsSMTP();
        $this->Host = 'smtp.hostinger.com';//Aqui el server
        $this->Port = 465;
        $this->SMTPAuth = true;
        $this->Username = $this->gCorreo;
        $this->Password = $this->gContrasena;
        $this->From = $this->gCorreo;
        $this->SMTPSecure = 'ssl';
        $this->FromName = $this->tu_nombre = "Ticket Asignado ".$id;
        $this->CharSet = 'UTF8';
        $this->addAddress($correo);
        $this->addAddress($this->admin);
        $this->WordWrap = 50;
        $this->IsHTML(true);
        $this->Subject = "Ticket Asignado";
        //Igual//
        $cuerpo = file_get_contents('../public/AsignarTicket.html'); /*template */

        $cuerpo = str_replace("xnroticket", $id, $cuerpo);
        $cuerpo = str_replace("lblNomUsu", $usu, $cuerpo);
        $cuerpo = str_replace("lblTitu", $titulo, $cuerpo);
        $cuerpo = str_replace("lblCate", $categoria, $cuerpo);
        $this->Body = $cuerpo;
        $this->AltBody = strip_tags("Ticket Asignado");
        return $this->Send();
    }

}
  • 1
    Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – Tangentially Perpendicular Sep 06 '22 at 04:26
  • Thanks, but I'm not using mail function. – Jason lozada Sep 06 '22 at 05:55
  • 1
    Nonetheless a lot of the points in there which relate to email in general and not to php could still be relevant – ADyson Sep 06 '22 at 06:14
  • 1
    Also phpmailer has a debug mode which produces extensive logs...have you used it yet? You can check the documentation for what to do – ADyson Sep 06 '22 at 06:15
  • Yes, i run an script for test, and works! but when i'm try to call the function, I'm not getting any error – Jason lozada Sep 06 '22 at 06:28
  • @jason There's much more to getting a mail system working than the exact method by which the server sends it. If you don't comply with the hosting company rules, configure SPF, DKIM and DMARC, take care with source and target addresses, structure your content carefully and a raft of other things your email can be unceremoniously blocked by a mail server and disappear without a trace. The top answer to the question I linked to covers a range of the most likely reasons for mail to fail. The use of `mail()` is just one. – Tangentially Perpendicular Sep 06 '22 at 07:11
  • Yes, but as I said I have already contacted support, I have configured everything, if I create a test script, it runs without problem, the mail is sent, my problem is when the controller calls the model, it does but for some reason the mail is not sent, as I commented that the same settings work on my local server. I even tried to put the test script inside the function but it is not sent either. I tried using composer and again it works in local but not in the hosting provider. – Jason lozada Sep 06 '22 at 07:20
  • 1
    You're using a very old and unsupported version of PHPMailer. [Get the latest version](https://github.com/PHPMailer/PHPMailer), and perhaps learn to use composer while you're at it. You have no error checking, so you won't know if things fail, or why, so I suggest you base your code on [the examples provided](https://github.com/PHPMailer/PHPMailer/tree/master/examples). – Synchro Sep 06 '22 at 07:21
  • Finally i get this error: SMTP ERROR: Failed to connect to server: (0)
    SMTP connect() failed. I'm going to find a solution
    – Jason lozada Sep 06 '22 at 08:58
  • Thanks a lot to everyone! I have fixed the error: I corrected permissions in the hosting, Upgraded to the latest version of phpmailer, For some reason port 587 does not work with my script (no idea with the test t works), so I used port 465. I appreciate the link to the troubleshoot inside the phpmailer debug, it helped me to understand the connection error. – Jason lozada Sep 06 '22 at 09:08

0 Answers0