Phpmailer error: Hostnet configuration

Asked

Viewed 530 times

0

follows the used code taken from the latest version of github I found

    <?php

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
require 'PHPMailer/Exception.php';

$mail = new PHPMailer(true);                             
try {
    //Server settings
    $mail->SMTPDebug = 2;                               
    $mail->isSMTP();                                      
    $mail->Host = 'smtp.dominiodahostnet.com.br';              
    $mail->SMTPAuth = true;                              
    $mail->Username = 'usuario=dominiodahostnet.com.br';                 
    // SMTP username
    $mail->Password = '****';                                   
    //$mail->SMTPSecure = 'tls';                          
    $mail->Port = 587;                                    

    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'Joe User');   
    //$mail->addAddress('[email protected]');               l
    //$mail->addReplyTo('[email protected]', 'Information');
    //$mail->addCC('[email protected]');
    //$mail->addBCC('[email protected]');

    //Attachments
    //$mail->addAttachment('/var/tmp/file.tar.gz');         
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    
    //Content
    $mail->isHTML(true);                                 
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}

Below the error generated

2017-09-20 17:58:23 SERVER -> CLIENT: 220 smtpq.f1.k8.com.br ESMTP Postfix
2017-09-20 17:58:23 CLIENT -> SERVER: EHLO www.dominiodahostnet.com.br
2017-09-20 17:58:23 SERVER -> CLIENT: 250-smtpq.f1.k8.com.br250-PIPELINING250-SIZE 33554432250-ETRN250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2017-09-20 17:58:23 CLIENT -> SERVER: STARTTLS
2017-09-20 17:58:23 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2017-09-20 17:58:23 CLIENT -> SERVER: QUIT
2017-09-20 17:58:23 SERVER -> CLIENT: 
2017-09-20 17:58:23 SMTP ERROR: QUIT command failed: 
SMTP Error: Could not connect to SMTP host.
Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.

Warning that I am performing the tests directly from the server and not by the localhost

  • 1

    It wouldn’t be $mail->Username = 'dominiodahostnet.com.br'; instead of $mail->Username = 'usuario=dominiodahostnet.com.br';

  • No, the Use name of the Hostnet server and this way

  • Okay, one more acquired knowledge

2 answers

4

The door 587 is usually a port that uses SSL or TLS, so you should uncomment the $mail->SMTPSecure and first test tls:

$mail->SMTPSecure = 'tls';

If the test fails ssl:

$mail->SMTPSecure = 'ssl';

If the error message is still:

Could not connect to SMTP host.

It’s probably because the extension for secure connections is commented on in php.ini:

If it is Windows Server:

;extension=php_openssl.dll

If it is Linux/Unix:

;extension=openssl.so

Remove the ; and restart Apache or Ngnix, if you have no control over the server and php.ini only by contacting their support.

Whether to not use TLS/SSL encryption

To disable the STARTTLS and/or secure connection adjust Phpmailer so:

$mail->SMTPSecure = false;
$mail->SMTPAutoTLS = false;

Extra note

That line seems wrong:

$mail->Username = 'usuario=dominiodahostnet.com.br';

I believe the right thing to do:

$mail->Username = '[email protected]';

Or without the domain:

$mail->Username = 'usuario';
  • the server does not use connection security, either tls or ssl. Uncoupling the $mail->Smtpsecure = 'tls'; error message give the same, and when replace to ssl gave the following: 2017-09-20 18:51:51 SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent. Error message: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

  • About the Username and the same thing, the server tells me to put this way using = instead of @.

  • 1

    @Julianosilveira tries this $mail->SMTPSecure = false;&#xA;$mail->SMTPAutoTLS = false;

  • I made the change to make the TLS fake, but now an error occurs when the server tries to send the message to the sender giving the following problem SERVER -> CLIENT: 554 5.7.1 <Unknown[179.223.237.28]>: Client host Rejected: Access denied. I will update the question for this new problem

  • @Julianosilveira Access denied is probably the Username or password that are wrong.

  • Worse than looking like yes, I am changing the Username and password to see what happens and the message will not change

  • @Julianosilveira tries to change the Username format using the @ instead of = and if it doesn’t work try to remove everything after the =, in other words using only so $mail->Username = 'usuario';, if none of the 2 works out send me the name of the hosting you use so I can search for the documentation and try to help you.

  • do not know if influences more the resulting ip of the unknown client [<Unknown[179.223.237.28]>] does not have smtp connection

  • 1

    @Julianosilveira is using https://www.hostnet.com.br/ ? If you access this https://www.hostnet.com.br/config.email/ generate the manual and send it to me "generated" to try to configure phpmailer for you.

  • Thanks @Julianosilveira I was able to make it work by following this tutorial https://www.hostnet.com.br/info/funcao-mail-do-php/#Configuring

  • Hostnet needs to release the sending of email via the dashboard. so the password and username didn’t work, because it should be pulled from the configuration generated by the panel and not by Phpmailer

  • Thank you, William Nascimento for your tip. For weeks I have been looking for a solution to this email sending error from the Hostnet server. After Phpmailer was upgraded to version 6.0.1, I could no longer send email through my website form. After much searching for an answer over the internet, I found your tip on this site (stackoverflow). As soon as I added it to my PHP code, it solved the problem!

Show 7 more comments

0

For anyone who finds the same problem I do.

Php file:

    <?php

    // Import PHPMailer classes into the global namespace
    // These must be at the top of your script, not inside a function
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;

    //Load composer's autoloader
    require 'PHPMailer/PHPMailer.php';
    require 'PHPMailer/SMTP.php';
    require 'PHPMailer/Exception.php';

    $mail = new PHPMailer(true);                             
    try {
        //Server settings
        $mail->SMTPDebug = 2;                               
        $mail->isSMTP();                                      
        $mail->Host = 'smtp.dominiodahostnet.com.br';              
        $mail->SMTPAuth = true;                              
        $mail->Username = 'usuario=dominiodahostnet.com.br';                 
        // SMTP username
        $mail->Password = '****';                                   
        //$mail->SMTPSecure = 'tls';                          
        $mail->Port = 587;                                    

        //Recipients
        $mail->setFrom('[email protected]', 'Mailer');
        $mail->addAddress('[email protected]', 'Joe User');   
        //$mail->addAddress('[email protected]');               l
        //$mail->addReplyTo('[email protected]', 'Information');
        //$mail->addCC('[email protected]');
        //$mail->addBCC('[email protected]');

        //Attachments
        //$mail->addAttachment('/var/tmp/file.tar.gz');         
        //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    
        //Content
        $mail->isHTML(true);                                 
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }

File .user.ini

        authmail.debug = Off
         authmail.port = 587
         authmail.address = "[email protected]"
         authmail.smtp_account = "exemplo=seudominio.com"
         authmail.smtp = "smtp.seudominio.com"
         authmail.password = "Aqui-você-coloca-a-senha-do-seu-e-mail"

the .user.ini file should be generated in the copied Hostnet panel and pasted into a note block.

completed this just play via ftp in hosting and test

Browser other questions tagged

You are not signed in. Login or sign up in order to post.