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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.