-1

Hi i am getting this message i dont know where is the problem. In my php.ini i have uncommented the line with extension=php_openssl.dll but it still not working. Any advice is welcome.

Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.

<?php
require 'class.phpmailer.php';

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';                 // Specify main and backup server
$mail->Port = 465;                                    // Set the SMTP port
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'mattoni.resta.test@gmail.com';                // SMTP username
$mail->Password = 'mattonirestaurace';                  // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'mattoni.resta.test@gmail.com';
$mail->FromName = 'Your From name';
$mail->AddAddress('josh@example.net', 'Josh Adams');  // Add a recipient
$mail->AddAddress('ellen@example.com');               // Name is optional

$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';
?>
george
  • 179
  • 2
  • 5
  • 16
  • You've based your code on an obsolete example, and you're using an old version of PHPMailer. [Get the latest](https://github.com/PHPMailer/PHPMailer) and read the docs and examples that come with it. In future, search before posting. – Synchro Jun 28 '16 at 08:55
  • Possible duplicate of [PHPMailer: SMTP Error: Could not connect to SMTP host](http://stackoverflow.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host) – Synchro Jun 28 '16 at 08:56

1 Answers1

0

actually, your code is correct.thing is you've to change settings in gmail..! enter image description hereenter image description here