How to send emails with Symfony 4 Swiftmailer from a local machine running on Windows 10?
Asked Answered
H

1

-1

I'm trying to send emails with Symfony 4, Wamp and fake sendmail on Windows 10 but without success, I'm hosted on OVH. I want to specify that I have a site hosted on OVH with same parameters running on Symfony 2 and Swiftmailer works perfectly.

Here is my Symfony .env line for Swiftmailer:

MAILER_URL=smtp://smtp.dnimz.com:465?encryption=ssl&auth_mode=login&[email protected]&password=***

Here is part of my Symfony controller for Swiftmailer:

$message = (new \Swift_Message('Hello Email'))
    ->setFrom(array($this->container->getParameter('mailer_user') => 'dnimz'))
    ->setTo($user->getEmail())
    ->setBody(
        $this->renderView(
            'emails/email_registration.html.twig',
            array('username' => $user->getUsername())
        ),
        'text/html'
    );

try {
    $this->get('mailer')->send($message);    
    $this->addFlash('notice', 'mail envoyé !');
} catch (\Exception $e) {
    $this->addFlash(
        'notice',
        '<strong>Le message n\'a pu être envoyé !</strong>'
    );
}

Here is my sendmail.ini from fake sendmail:

[sendmail]

smtp_server=smtp.dnimz.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
[email protected]
auth_password=***
pop3_server=
pop3_username=
pop3_password=
force_sender=
force_recipient=
hostname=

Here is my php.ini mail function part:

SMTP =smtp.dnimz.com
smtp_port =465
sendmail_from = "[email protected]"
sendmail_path = "C:/wamp64/sendmail/sendmail.exe"
mail.add_x_header = On

When sending the email, I've got this warnings and error:

[debug] Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

2017-12-29T18:44:09+00:00 [debug] Warning: stream_socket_client(): Failed to enable crypto

2017-12-29T18:44:09+00:00 [debug] Warning: stream_socket_client(): unable to connect to ssl://smtp.dnimz.com:465 (Unknown error)

2017-12-29T18:44:09+00:00 [error] Exception occurred while flushing email queue: Connection could not be established with host smtp.dnimz.com [ #0]

I don't know why these errors occur?

Hooghly answered 29/12, 2017 at 19:0 Comment(0)
J
0

It looks like you either don't have OpenSSL installed or there is a certificate error. I remember a similar issue as the first warning regularly occuring with composer on Windows. The solution was to install a missing certificate (just place it in your certs folder in your WAMP-installation).

For reference see:

Junina answered 29/12, 2017 at 20:30 Comment(1)
Thank you dbrumann but it didn't solve the problem and Composer works fine, I'm still working on this...Hooghly

© 2022 - 2024 — McMap. All rights reserved.