0

I am unable to send an email on my local server.

I used following phpmailer code to test mail sending:

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "tls";                 
$mail->Host       = "smtp.gmail.com";      // SMTP server
$mail->Port       = 587;                   // SMTP port
$mail->Username   = "";  // username
$mail->Password   = "";            // password

$mail->SetFrom('', 'Test');

$mail->Subject    = "I hope this works!";

$mail->MsgHTML('Blah');

$address = "";
$mail->AddAddress($address, "Test");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

But I get the following error:
2020-07-06 09:20:08 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP y7sm6517117pjy.54 - gsmtp
2020-07-06 09:20:08 CLIENT -> SERVER: EHLO localhost
2020-07-06 09:20:08 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [157.49.67.14]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2020-07-06 09:20:08 CLIENT -> SERVER: STARTTLS
2020-07-06 09:20:08 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2020-07-06 09:20:09 CLIENT -> SERVER: QUIT
2020-07-06 09:20:09
2020-07-06 09:20:09
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Please suggest possible solutions.

  • Does this answer your question? [Send email from localhost running XAMMP in PHP using GMAIL mail server](https://stackoverflow.com/questions/19132171/send-email-from-localhost-running-xammp-in-php-using-gmail-mail-server) – urfusion Jul 06 '20 at 09:51
  • You see that link in the error message to the troubleshooting guide? Click it. – Synchro Jul 06 '20 at 10:04
  • Tried with suggested answer by @urfusion but failed to send mail – Adithya Baliga Jul 09 '20 at 17:41

0 Answers0