regarding php script is not getting executed

RMAG news

Hi,

When I am trying to execute below php script using a html webpage but it’s not getting executed instead of this it points to the script itself.

here is that php script:-


<?php
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;

require ‘E:/SW/XAMPP Installation/htdocs/fl1/PHPMailer-6.9.1/PHPMailer-6.9.1/src/Exception.php’;
require ‘E:/SW/XAMPP Installation/htdocs/fl1/PHPMailer-6.9.1/PHPMailer-6.9.1/src/PHPMailer.php’;
require ‘E:/SW/XAMPP Installation/htdocs/fl1/PHPMailer-6.9.1/PHPMailer-6.9.1/src/SMTP.php’;

// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set(‘display_errors’, 1);

// Check if the form was submitted
if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
// Form data
$name = $_POST[‘name’];
$phone = $_POST[‘phone’];
$email = $_POST[’email’];
$message = $_POST[‘message’];

// Initialize PHPMailer
$mail = new PHPMailer(true);

try {
// Server settings
$mail->isSMTP();
$mail->Host = ‘smtp.gmail.com’; // Change this to your SMTP server hostname
$mail->SMTPAuth = true;
$mail->Username = ‘my gmail email id’; // Change this to your email address
$mail->Password = ‘mypassword’; // Change this to your email password
$mail->SMTPSecure = ‘tls’;
$mail->Port = 587;

// Sender and recipient
$mail->setFrom($email, $name); // Use client’s email and name as sender
$mail->addAddress(‘receipient gmail id’); // Change this to the recipient email address

// Content
$mail->isHTML(true);
$mail->Subject = “Message from $name”;
$mail->Body = “Name: $name<br>Phone: $phone<br>Email: $email<br>Message: $message”;

// Send email
$mail->send();
echo “Thank you! Your message has been sent.”;
} catch (Exception $e) {
echo “Oops! Something went wrong: {$mail->ErrorInfo}”;
}

} else {
// Redirect back to the contact form if accessed directly
header(“Location: index.html”);
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *