Smtp Error: Could Not Connect To Smtp Host.

hi, i am trying to send email (with phpMailer )from my yii application through gmail smtp but i got the error (SMTP Error: Could not connect to SMTP host. ) here is my code can any one tell me what is wrong with this, tnx in advance :)

Yii::import(‘application.extensions.phpmailer.JPhpMailer’);

$mail = new JPhpMailer;


$mail->IsSMTP();


$mail->Host = 'smtp.gmail.com';


$mail->Port= '465';


	$mail->SMTPSecure = "ssl";


$mail->SMTPSecure = true;


$mail->Mailer="smtp";


$mail->SMTPAuth = true;


$mail->Username = 'myAdress@gmail.com';


$mail->Password = 'myPassword';


$mail->SetFrom('myAddress@gmail.com', 'Noor Alam');


$mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';


$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';


$mail->MsgHTML('<h1>JUST A TEST!</h1>');


$mail->AddAddress('myotheraccount@yahoo.com', 'Noor Alam');


$mail->Send();

See if any of the information on this page helps. It would be a good idea to turn on SMTPDebug as shown.

:( Still not working do i need any configuration for this in my email or in yii applications i m running it on localhost, errors are

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1542350895)

SMTP Error: Could not connect to SMTP host. SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1542350895)

SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

Isn’t the error clear enough? You don’t have open ssl installed/enabled on your server, install/enable it and try again.

i have enabled extension=php_openssl.dll from php.ini but still the same error :(

i have done it successfully by swift mailer thanks to @twisted1919 :)

i am going to tell you the steps

  1. Uncomment [extension=php_openssl.dll] in php.ini

  2. download swift mailer and extract it to your extenstions

  3. in config add the following lines in components section

    ‘swiftMailer’ => array(

     'class' => 'ext.swiftMailer.SwiftMailer',
    
    
     ),
    
  4. now where you want to perform this action do the following

require_once Yii::getPathOfAlias(‘application.extensions’) . ‘/swiftMailer/lib/swift_required.php’;

// Create the Transport

$transport = Swift_SmtpTransport::newInstance(‘smtp.gmail.com’, 465, ‘ssl’)

->setUsername(‘myAdress@gmail.com’) [your gmail email from which you want to send email ]

->setPassword(‘myPassword’); [password of your email]

// Create the Mailer using your created Transport

$mailer = Swift_Mailer::newInstance($transport);

// Create a message

$message = Swift_Message::newInstance(‘PHPMailer Test Subject via smtp, basic with authentication’)

->setFrom(array(‘myAdress@gmail.com’ => ‘John Doe’)) [your address]

->setTo(array(‘myotheraccount@yahoo.com’ => ‘Noor Alam’)) [ Recipient address]

->setBody(’<h1>JUST A TEST!</h1>’, ‘text/html’);

// Send the message

$result = $mailer->send($message);

Enjoy… !!!