I have installed PHP Mailer in Ubuntu 16 and not being able to send email can someone please help me?

Here is my code.

<?php
require '/Mailer/class.phpmailer.php';
require '/Mailer/class.smtp.php';

$mail = new PHPMailer;
$mail->setFrom('');
$mail->addAddress('me@example.com');
$mail->Subject = 'Message sent by Test';
$mail->Body = 'Hello! This is a TEST';
$mail->IsSMTP();
$mail->SMTPSecure = 'ssl';
$mail->Host = 'ssl://smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Port = 465;

//Set your existing gmail address as user name
$mail->Username = 'example@gmail.com';

//Set the password of your gmail address here
$mail->Password = '*********';
if(!$mail->send()) {
  echo 'Email is not sent';
  echo 'Email error: ' . $mail->ErrorInfo;
} else {
  echo 'Email has been sent.';
}
?>

Have you tried enabling verbose debug output?

$mail->SMTPDebug = 2; 

Sir,
This is what shows after

2021-08-18 06:04:37 SMTP ERROR: Failed to connect to server: (0) 2021-08-18 06:04:37 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Email is not sentEmail error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Are you sure that’s right. I wasn’t aware ssl was a valid protocol.

Have you tried this testing program?

Sir,
The problem was in firewall checked and now working thank you.

2 Likes

Glad to hear you’ve got it working now.

It is as far as PHP Mailer is concerned :slight_smile:

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.