How can PHP be used to create a mail interface within Typo 3 that allows for file attachments in emails?

To create a mail interface within Typo3 that allows for file attachments in emails, you can use PHP to handle the file uploading and attachment process. You would need to create a form where users can input their email address, message, and attach files. Then, use PHP to handle the form submission, process the file uploads, and send the email with the attachments.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $to = "recipient@example.com";
    $subject = "Email with Attachment";
    $message = $_POST['message'];
    
    $file_name = $_FILES['attachment']['name'];
    $temp_file = $_FILES['attachment']['tmp_name'];
    $file_path = "uploads/" . $file_name;
    
    if (move_uploaded_file($temp_file, $file_path)) {
        $file = $file_path;
        $content = file_get_contents($file);
        $content = chunk_split(base64_encode($content));
        
        $header = "Content-Type: application/octet-stream; name=\"" . $file_name . "\"\r\n";
        $header .= "Content-Transfer-Encoding: base64\r\n";
        $header .= "Content-Disposition: attachment; filename=\"" . $file_name . "\"\r\n";
        
        $attachment = "--PHP-mixed-" . md5(time()) . "\r\n" . $header . "\r\n" . $content . "\r\n";
        
        $header = "From: sender@example.com\r\n";
        $header .= "MIME-Version: 1.0\r\n";
        $header .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-" . md5(time()) . "\"\r\n";
        
        $message = "--PHP-mixed-" . md5(time()) . "\r\n";
        $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
        $message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
        $message .= $message . "\r\n";
        $message .= $attachment;
        
        mail($to, $subject, $message, $header);
        
        echo "Email sent with attachment successfully.";
    } else {
        echo "Failed to upload file.";
    }
}
?>