PHP Mailer Does Not Work Localhost

Asked

Viewed 1,182 times

2

I don’t understand why the PHP Mailer does not work on my Localhost. It’s like this:

# 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 mistake:

stream_socket_enable_crypto(): Peer Certificate CN=`*. uni5.net' Did not match expected CN='smtp.dominio.com.br''

It’s right the SMTP. In Laravel I also use this same email, user and password and it works. In Smtpsecure I have to get the TLS.

But localhost gives this error. I haven’t tried it on the network yet.

  • 1

    do you have an email server installed on your localhost? Maybe this is it.

  • I don’t know how to see that, but I believe so, because Lavarel also uses and works.

  • 1

    On my localhost works perfectly, n know which server vc uses, I am using usb webserver, try to check your settings.

1 answer

3


The Phpmailer you need to define if it is to verify the certificate or not. I understand that you do not have any by the code you present and by being in localhost, so I suggest that in its definitions:

<?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 on $mail->Host who certainly has a certificate.

  • 2

    Wow, now I’ve seen who’s who on this Yahoo Improved Answers. It worked out doing that. Thank you so much.

  • 1

    @Taopaipai happy to have been able to help you!

  • It helped me a lot too! ;-) Thank you!

Browser other questions tagged

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