Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...