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

雨燕双飞 提交于 2020-01-07 09:19:32

问题


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&username=simslay@dnimz.com&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
auth_username=simslay@dnimz.com
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 = "simslay@dnimz.com"
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?


回答1:


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:

  • https://akrabat.com/ssl-certificate-verification-on-php-5-6/
  • Composer update fails while updating from packagist
  • https://github.com/composer/composer/issues/2798#issuecomment-59812991


来源:https://stackoverflow.com/questions/48027178/how-to-send-emails-with-symfony-4-swiftmailer-from-a-local-machine-running-on-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!