SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed


I am trying to send an email using Mailer but getting below error


Connection: opening 2017-05-25 08:22:07 SMTP ERROR: Failed to connect   to server: (0) SMTP connect() failed. Mailer Error: SMTP connect()   failed.


php_openssl extension & IMAP both are enabled. I tried to find it on google but still no luck.


function sendMail($subject=''$to=''$emailcontent=''