0
votes

Trying to send email in php.

transport: smtp
host: smtp.gmail.com
username: [email protected]
password: password
port: 587
encryption: ssl

Options already tried:

  1. Tried all combinations of port (22, 465, 587) and encryption (No encryption, SSL, TLS)
  2. Allow access to less secure apps is on and two ways authentication is off.
  3. checked host details: enter image description here

    and tried with above host name and ips.

  4. Tested mailtrap.io and its working fine! (receiving email in mailtrap inbox, so no issue in code)

  5. I'm using same gmail account in another .net application and its working fine over there.

What could be the option left to try?

3
are you getting the above exception on localhost or live domain?Muhammad Omer Aslam

3 Answers

0
votes

I use this and work

    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        'useFileTransport' => false,//set this property to false to send mails to real email addresses
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => '[email protected]', // a valid gmail account
            'password' => 'your_password', // the related  passwordd
            'port' => '587',
            'encryption' => 'tls',
        ],
0
votes

Added this line in streamBuffer.php and it worked!

$options = array_merge($options, array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false)));
0
votes

Added this line in streamBuffer.php and it worked!

$options = array_merge($options, array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false)));

Don't disable ssl certificate verification - this will open you to MITM attacks.

I'm pretty sure that Gmail has correct certificate, so you should try to fix this at your end.

  1. Make sure that you have proper Certificate authority bundle at your server.
  2. If you're behind some trusted proxy which works like MITM, you should add proxy's certificate to your trusted certificates.

You may want to look at How to update cURL CA bundle on RedHat?, How do you add a certificate authority (CA) to Ubuntu? or similar instructions related to your system.

Also, take a look at similar issue at Composer bug tracker.