PHP Mailer Does Not Work Localhost

2

I do not understand why the PHP Mailer library does not work on my Localhost. Here's how:

# Envia Emails Para Departamento Escolhido e para o Admin
$mail               = new PHPMailer;
$mail->isSMTP();
$mail->Host         = 'smtp.dominio.com.br'; # 'dominio' é só um pseudo
$mail->SMTPAuth     = true;
$mail->SetLanguage('br');
$mail->Username     = '[email protected]';
$mail->Password     = 'dominio123';
$mail->SMTPSecure   = '';
$mail->Port         = 587;

And give me the following error:

  

stream_socket_enable_crypto (): Peer certificate CN = '* .uni5.net' did not match expected CN = 'smtp.domain.com' ''

SMTP is right. In Laravel I also use this same email, username and password and it works. In SMTPSecure I have to remove the TLS .

But localhost gives this error. I have not tested the network yet.

    
asked by anonymous 23.11.2015 / 14:02

1 answer

3

PHPMailer requires you to set whether to verify the certificate or not. I realize that you do not have any of your code that has and is in localhost , so I suggest that in the definitions it says:

<?php
    (...)
    $mail->SMTPOptions = array(
       'ssl' => array(
           'verify_peer' => false,
           'verify_peer_name' => false,
           'allow_self_signed' => true
        )
    );
    (...)
?>

The other alternative is to put the actual server host in $mail->Host , which certainly has a certificate.

    
23.11.2015 / 15:26