pranshu82202 Posted July 31, 2011 Share Posted July 31, 2011 I am trying to create a mail script to send mails via gmail on my localhost. But every time i get the following error : SMTP Error: Could not connect to SMTP host. Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host. Here is my code : <?php require("class.phpmailer.php"); // path to the PHPMailer class $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->Mailer = "smtp"; $mail->Host = "ssl://smtp.gmail.com"; $mail->Port = 465; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "[email protected]"; // SMTP username $mail->Password = "***********"; // SMTP password $mail->From = "[email protected]"; $mail->AddAddress("[email protected]"); $mail->Subject = "First PHPMailer Message"; $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer."; $mail->WordWrap = 50; if(!$mail->Send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } ?> I am using xampp. And installed PHPMailer_v5.1 in the htdocs folder. ANd i have used my gmail username and password in $mail->Username, $mail->Password. Please heal the issue. Quote Link to comment https://forums.phpfreaks.com/topic/243363-could-not-connect-to-smtp-host/ Share on other sites More sharing options...
IrOnMaSk Posted August 1, 2011 Share Posted August 1, 2011 Pran, did you allow the openssl.dll in your php.ini? Gmail uses secure socket, so you have to enable it in php.ini... search for extension=php_openssl.dll and uncomment it if you haven't already, it should works Quote Link to comment https://forums.phpfreaks.com/topic/243363-could-not-connect-to-smtp-host/#findComment-1250313 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.