skip to Main Content

I’m using Windows 10 with cmd.

When I’m starting my index.php file, using php index.php I’m getting this error:

PHP Fatal error:  Uncaught Swift_TransportException: Connection could not be established with host ssl://smtp.gmail.com :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportStreamBuffer.php:269 Stack trace:
#0 [internal function]: Swift_Transport_StreamBuffer->{closure}(2, 'stream_socket_c...', 'C:\Users\barte\...', 272, Array)
#1 C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportStreamBuffer.php(272): stream_socket_client('ssl://smtp.gmai...', 0, '', 30, 4, Resource id
#98)
#2 C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportStreamBuffer.php(58): Swift_Transport_StreamBuffer->establishSocketConnection()
#3 C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportAbstractSmtpTransport.php(143): Swift_Transport_Strea in C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportStreamBuffer.php on line 269

Fatal error: Uncaught Swift_TransportException: Connection could not be established with host ssl://smtp.gmail.com :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportStreamBuffer.php:269 Stack trace:
#0 [internal function]: Swift_Transport_StreamBuffer->{closure}(2, 'stream_socket_c...', 'C:\Users\barte\...', 272, Array)
#1 C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportStreamBuffer.php(272): stream_socket_client('ssl://smtp.gmai...', 0, '', 30, 4, Resource id
#98)
#2 C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportStreamBuffer.php(58): Swift_Transport_StreamBuffer->establishSocketConnection()
#3 C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportAbstractSmtpTransport.php(143): Swift_Transport_Strea in C:UsersbarteDesktopPHP3vendorswiftmailerswiftmailerlibclassesSwiftTransportStreamBuffer.php on line 269

My index.php file:

<?php

require "vendor/autoload.php";

$transport = new Swift_SmtpTransport("ssl://smtp.gmail.com", 465);
$transport->setUsername("mymail");
$transport->setPassword("******");

$mailer = new Swift_Mailer($transport);

$message = new Swift_Message();
$message
    ->setFrom("[email protected]")
    ->setTo("[email protected]")
    ->setSubject("Hello!")
    ->setBody("Hello, this is example body");

$mailer->send($message);

Here’s my composer.json file:

{
    "name": "bartek/3",
    "authors": [
        {
            "name": "Bartek",
            "email": "[email protected]"
        }
    ],
    "require": {
        "swiftmailer/swiftmailer": "^6.2"
    }
}


When I’m typing composer –version I’m getting:

PHP temp directory (C:UsersbarteAppDataLocalTemp) does not exist
or is not writable to Composer. Set sys_temp_dir in your php.ini
Composer version 1.10.5 2020-04-10 11:44:22

Thanks

3

Answers


  1. ssl://smtp.gmail.com is not a proper address for a mailserver. What happens if you skip the protocol and just use smtp.gmail.com?

    Login or Signup to reply.
  2. I prepare code recently for this purpose
    For TLS

    $transport = (new Swift_SmtpTransport('smtp.gmail.com', 587,'tls'))
    ->setUsername('[email protected]')
    ->setPassword('password');
    

    And For SSL

    $transport = (new Swift_SmtpTransport('smtp.gmail.com', 25,'ssl'))
    ->setUsername('[email protected]')
    ->setPassword('password');
    
    Login or Signup to reply.
  3. I solved it. The problem was, I typed the password to my Google account, but I should paste the password generated in "App passwords" in google account settings there. You can generate a password like this by going to Google Account Settings > Security > App passwords

    Note: You have to have 2-step verification enabled first. Otherwise App passwords won’t show up.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search