D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
etb1lp46s9ed
/
public_html
/
kudlaastraproductions.com
/
Filename :
send-email.php
back
Copy
<?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'vendor/autoload.php'; // Load environment variables (basic implementation for demo) // In a real production environment, use a library like vlucas/phpdotenv $smtp_host = 'smtp.example.com'; $smtp_user = 'your-email@example.com'; $smtp_pass = 'your-password'; $smtp_port = 587; header('Content-Type: application/json'); if ($_SERVER["REQUEST_METHOD"] == "POST") { // Get JSON input $json = file_get_contents('php://input'); $data = json_decode($json, true); $name = $data['name'] ?? ''; $email = $data['email'] ?? ''; $phone = $data['phone'] ?? ''; $message = $data['message'] ?? ''; if (empty($name) || empty($email) || empty($message)) { http_response_code(400); echo json_encode(["message" => "Please fill all required fields."]); exit; } $mail = new PHPMailer(true); try { //Server settings $mail->isSMTP(); $mail->Host = $smtp_host; $mail->SMTPAuth = true; $mail->Username = $smtp_user; $mail->Password = $smtp_pass; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = $smtp_port; //Recipients $mail->setFrom($email, $name); $mail->addAddress('business@astragroup.co.in'); //Content $mail->isHTML(true); $mail->Subject = 'New Contact Form Submission - Astra Productions'; $mail->Body = "<p><strong>Name:</strong> $name</p> <p><strong>Email:</strong> $email</p> <p><strong>Phone:</strong> $phone</p> <p><strong>Message:</strong> $message</p>"; $mail->AltBody = "Name: $name\nEmail: $email\nPhone: $phone\nMessage: $message"; $mail->send(); echo json_encode(["message" => "Email sent successfully"]); } catch (Exception $e) { http_response_code(500); echo json_encode(["message" => "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"]); } } else { http_response_code(405); echo json_encode(["message" => "Method Not Allowed"]); } ?>