Jump to content

Could not connect to SMTP host


pranshu82202

Recommended Posts

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 = "sender@gmail.com"; // SMTP username
$mail->Password = "***********"; // SMTP password 

$mail->From     = "sender@gmail.com";
$mail->AddAddress("reciever@gmail.com");  

$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.

Link to comment
https://forums.phpfreaks.com/topic/243363-could-not-connect-to-smtp-host/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.