SMTP error when sending email

0

I'm trying to upload to a page of a site, and the following error is appearing: SMTP Error: Could not connect to SMTP host.

I was checking the site code, and it is sending emails with PHPMailer. The settings are below.

$mail->SMTPAuth   = true;
$mail->Host       = "mail.MEUSITE.com.br";
$mail->Port       = 587;
$mail->Username   = "[email protected]";
$mail->Password   = "SENHA";

Is there something wrong?

    
asked by anonymous 25.04.2018 / 15:53

2 answers

0

Have you tried checking ssl and tls, as below:

If you use TLS, add:

$mail->SMTPSecure = 'tls';

If you use SSL, add:

$mail->SMTPSecure = 'ssl';
    
25.04.2018 / 15:58
0

Some services require authorization to do this. Just as an example: gmail, you need to go into settings and change in order to use SMTP.

In any case, follow an example using the PHPMailer library:


    require 'PHPMailer/PHPMailerAutoload.php';
    $mail = new PHPMailer();
    $mail->isSMTP();
    $mail->SMTPDebug =2;// 0,1 ou 2
    $mail->Debugoutput = 'html';
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 587;
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "tls";
    $mail->Username = "[email protected]";
    $mail->Password = "senha";
    $mail->CharSet = 'UTF-8';
    $mail->setFrom('[email protected]', 'Informativo');
    $mail->addAddress('[email protected]', 'algum texto');
    $mail->addAddress('[email protected]', 'algum texto');
    $mail->addAddress('[email protected]', 'algum texto');
    $mail->Subject = 'assunto do email';

    $mensagem = 'Teste teste teste ';
    $mensagem .= 'outro teste';

    $mail->msgHTML($mensagem);

    $mail->AltBody = 'Caso você esteja lendo essa mensagem é provável que seu cliente de email não tenha suporte a HTML';
    if (!$mail->send()){
        echo "email NÃO enviado";
    }else {
        echo "email enviado com sucesso";
    }

    
26.04.2018 / 01:56