I try to implement PHPMailer on our school project system and i don't have idea how it work, just follow it from tutorial, but it can send email and it not also resulting error.
Please help my find the reason why this is not working on me and solve the error.
this is my code from tutorial:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//include ('includes/connection.php');
require 'PHPMailer/vendor/autoload.php';
$email = 'recipientemail@gmail.com';
/****************START EMAIL************/
$subject = "Try System";
$message = "<strong>Try:</strong> try try<br>
success success success!";
//Email start
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = true; // 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 = 'puvonlinesystem@gmail.com'; // SMTP username
$mail->Password = 'puv12345';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // SMTP password
$mail->SMTPSecure = 'tls';//'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;//587; // TCP port to connect to
//Recipients
$mail->setFrom('myemail@gmail.com');
$mail->addAddress($email);
//$mail->addCC('example@gmail.com');
// Attachments
//$mail->addStringAttachment($pdf,'resconfirmation.pdf');
// Add attachments
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
//Email stop
/****************STOP EMAIL************/
?>
And this is the result on my page:
Sending with mail()
Sendmail path: /usr/sbin/sendmail -t -i
Envelope sender: myemail@gmail.com
To: recipientemail@gmail.com
Subject: Try System
Headers: Date: Thu, 29 Apr 2021 04:43:38 -0400From: puvonlinesystem@gmail.comMessage-ID: <X2yzXw5J0mmkEBVXPtwf92LmQtV8vixdTVdDczcZag@puvonlinesystem.ml>X-Mailer: PHPMailer 6.3.0 (https://github.com/PHPMailer/PHPMailer)MIME-Version: 1.0Content-Type: text/html; charset=iso-8859-1
Result: true