<?php
require 'PHPMailer-master/src/Exception.php';
require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (isset($_POST['sendmail'])) {
$mail = new PHPMailer(true);
try{
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'XXXX@gmail.com';
$mail->Password = 'XXXX';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('XXXX@gmail.com');
$mail->addAddress($_POST['email']);
$mail->Subject = $_POST['subject'];
$mail->isHTML(true);
$mail->Body = $_POST['message'];
$mail->send();
echo '<script>alert("Successfully Send!")</script>';
}catch(Exception $e){
echo '<script>alert("Message Error!")</script>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Notification</title>
<link rel="stylesheet" type="text/css" href="message_style.css">
</head>
<body>
</body>
<center>
<div>
<div>
<div>
<div class="header" style="margin-top: 4%;">
<h2 style="font-size: 25px;">Message</h2>
</div>
<form role="form" method="post" enctype="multipart/form-data">
<div>
<div >
<label for="email">Email To:</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email address" maxlength="50" autocomplete="off">
</div>
</div>
<div class="row">
<div>
<label class="subject" for="subject">Subject:</label>
<input type="text" class="form-control" id="subject" name="subject" placeholder="subject" maxlength="50" autocomplete="off">
</div>
</div>
<div>
<div>
<label class="message" for="name">Message:</label>
<textarea class="form-control" type="textarea" id="message" name="message" maxlength="6000" rows="4">Please Confirm my Payment...</textarea>
</div>
</div>
<div>
<div class="col-sm-9 form-group">
<button type="submit" name="sendmail" class="btn">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
</center>
<br><br><br><br><br><br><br><br>
</body>
</html>
“Message Error!” is showing when I try to send.
I would like also to attach an image or a file.