Send mail within a local server?

1

I have a site in my localhost and would like to be able to send emails. I tried the mail() function but I could not. Then I found a form using PHPMailer .

I have the following code

<?php

$oc=$_POST['razao'];
$rua=$_POST['rua'];
$freg=$_POST['freg'];
$texto = "
<h4>Declaração de uma Ocorrência</h4>
<br/>
<br/>
Ocorrência: ".$oc."<br/></br/>
Rua: ".$rua." da freguesia de ".$freg.";
";
require '../mail/PHPMailerAutoload.php';
echo "<script>console.log('".$texto."')</script>";
    $mail = new PHPMailer();

    $mail->CharSet="utf-8";
    $mail->IsSMTP();
    $mail->Host = "smtp.gmail.com";  // specify main and backup server
    $mail->Username = 'EMAIL';          // SMTP username
    $mail->Password = 'PASS'; // SMTP password
    $mail->SMTPSecure = 'tls';                  // Enable TLS encryption, 'ssl' also accepted
    $mail->Port = 587;                          // TCP port to connect to

    $mail->From = "[email protected]";
    $mail->FromName = "União de Freguesias de Antas e Abade de Vermoim";
    $mail->AddAddress("[email protected]", "Bruno Moutinho");
    $mail->IsHTML(true);

    $mail->Subject = "Declaração de uma Ocorrência";
    $mail->Body    = $texto;

    if(!$mail->Send())
    {
       echo "<script>console.log('".$mail->ErrorInfo."')</script>";
       exit;
    }else{
        echo "<script>console.log('Sucesso')</script>";
    }
?>

All variables get there right. Sending is done by ajax but I can not get it because it gives me an error in the console: SMTP connect() failed. .

    
asked by anonymous 03.11.2017 / 20:43

0 answers