-3

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require 'vendor/autoload.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'example@gmail.com';                 // SMTP username
    $mail->Password = 'passwordhere';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('example@gmail.com', 'Mailer');
    $mail->addAddress('example@gmail.com', 'Joe User');     // Add a recipient
   
   
    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

Here is phpmailer code ,this is not work and i am understand what is problem .. Whene i ma run this code thats show me error ...Error is Error show---- 2018-03-05 07:31:40 SERVER -> CLIENT: 2018-03-05 07:31:40 SMTP NOTICE: EOF caught while checking if connected SMTP Error: Could not connect to SMTP host. SMTP Error: Could not connect to SMTP host. Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.

  • Possible duplicate of [Phpmailer using smtp with Gmail not working - connection timing out](https://stackoverflow.com/questions/19216335/phpmailer-using-smtp-with-gmail-not-working-connection-timing-out) – Vishnu Bhadoriya Mar 05 '18 at 07:37
  • Search before posting. You can check whether you're being blocked by your ISP by reading [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) which tells you exactly how to do that. – Synchro Mar 05 '18 at 10:07

1 Answers1

0

If you are using TLS, please use port 587 instead.

SSL would be using port 465

And make sure php_openssl modules is enabled/uncommented in your php.ini

Adlan Arif Zakaria
  • 1,706
  • 1
  • 8
  • 13