<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/Exception.php';
require 'PHPMailer/SMTP.php';
require 'PHPMailer/PHPMailer.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$message = $_POST['message'];
try {
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'my username';
$mail->Password = 'my password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('from mail adress', 'Your Name');
$mail->addAddress('mail to address', 'Recipient Name');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = "Sender: $name. <br>
Email: $email. <br>
Subject: $subject. <br>
Message: $message.";
$mail->send();
echo "Message Sent Successfully!";
} catch (Exception $e) {
echo "Message Sending Failed!";
}
}
?>
i am using free hosting
i cant sending mail by using this code this problem i found in your domain hosting in others it works perfectly. what is the solution?